var egret = window.egret;var __reflect = (this && this.__reflect) || function (p, c, t) {
    p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __extends = this && this.__extends || function __extends(t, e) { 
 function r() { 
 this.constructor = t;
}
for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
r.prototype = e.prototype, t.prototype = new r();
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [0, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var GUser = (function () {
    function GUser() {
        this._nickName = "";
        this._userID = 0;
        this._token = "";
        this._avator = "";
        this._pointValue = 0;
        this._rank = 0;
    }
    Object.defineProperty(GUser.prototype, "nickName", {
        get: function () {
            return this._nickName;
        },
        set: function (_name) {
            this._nickName = _name;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GUser.prototype, "token", {
        get: function () {
            return this._token;
        },
        set: function (tok) {
            this._token = tok;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GUser.prototype, "avator", {
        get: function () {
            return this._avator;
        },
        set: function (ava) {
            this._avator = ava;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GUser.prototype, "pointValue", {
        get: function () {
            return this._pointValue;
        },
        set: function (value) {
            this._pointValue = value;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GUser.prototype, "rank", {
        get: function () {
            return this._rank;
        },
        set: function (rk) {
            this._rank = rk;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(GUser.prototype, "userID", {
        get: function () {
            return this._userID;
        },
        set: function (id) {
            this._userID = id;
        },
        enumerable: true,
        configurable: true
    });
    /**
 * 给用户添加假数据
 */
    GUser.explameAddPlayer = function () {
        var player1 = new GUser();
        player1.avator = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1526393669326&di=835161a2290b3b6ae1740bd39eb52f3e&imgtype=0&src=http%3A%2F%2Fimg5.duitang.com%2Fuploads%2Fitem%2F201609%2F16%2F20160916214658_UcHjJ.jpeg";
        player1.nickName = "微微";
        player1.pointValue = 10002;
        player1.userID = 85642;
        var player2 = new GUser();
        player2.avator = "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=913343495,873855432&fm=27&gp=0.jpg";
        player2.nickName = "小妞";
        player2.pointValue = 534;
        player2.userID = 75646;
        var player3 = new GUser();
        player3.avator = "https://img2.woyaogexing.com/2018/05/15/2bf1c62d1b036564!400x400_big.jpg";
        player3.nickName = "子琪";
        player3.pointValue = 6534;
        player3.userID = 96648;
        GlobalData.myUser = player1;
        var userlist = [];
        userlist.push(player1);
        userlist.push(player2);
        userlist.push(player3);
        return userlist;
    };
    return GUser;
}());
__reflect(GUser.prototype, "GUser");
var network;
(function (network) {
    var IResolver = (function () {
        function IResolver() {
        }
        /**
         * 封包
         */
        IResolver.prototype.toPackage = function (cmd, msg) {
            var dt = this.Package(msg);
            return JSON.stringify({
                action: cmd,
                data: dt
            });
            //return JSON.stringify(dt);
        };
        /**
         * 解包
         */
        IResolver.prototype.getParse = function (data) {
            try {
                return this.Parse(data);
            }
            catch (error) {
                console.error(error);
                return null;
            }
        };
        return IResolver;
    }());
    network.IResolver = IResolver;
    __reflect(IResolver.prototype, "network.IResolver");
})(network || (network = {}));
var network;
(function (network) {
    /**
     * S 后缀代表 发送，R代表接收
     */
    var NetMsgEvent;
    (function (NetMsgEvent) {
        NetMsgEvent[NetMsgEvent["GAME_READY_S"] = 120] = "GAME_READY_S";
        NetMsgEvent[NetMsgEvent["GAME_READY_R"] = 121] = "GAME_READY_R";
        NetMsgEvent[NetMsgEvent["RESET_ROOM_S"] = 122] = "RESET_ROOM_S";
        NetMsgEvent[NetMsgEvent["RESET_ROOM_R"] = 123] = "RESET_ROOM_R";
        NetMsgEvent[NetMsgEvent["CALL_LAND_S"] = 124] = "CALL_LAND_S";
        NetMsgEvent[NetMsgEvent["CALL_LAND_RN"] = 125] = "CALL_LAND_RN";
        NetMsgEvent[NetMsgEvent["CALL_LAND_RO"] = 126] = "CALL_LAND_RO";
        NetMsgEvent[NetMsgEvent["REPROT_SCORE_S"] = 128] = "REPROT_SCORE_S";
        NetMsgEvent[NetMsgEvent["REPROT_SCORE_R"] = 129] = "REPROT_SCORE_R";
        NetMsgEvent[NetMsgEvent["PLAY_CARDS_S"] = 130] = "PLAY_CARDS_S";
        NetMsgEvent[NetMsgEvent["PLAY_CARDS_R"] = 131] = "PLAY_CARDS_R";
        NetMsgEvent[NetMsgEvent["GAME_OVER_S"] = 132] = "GAME_OVER_S";
        NetMsgEvent[NetMsgEvent["GAME_OVER_R"] = 133] = "GAME_OVER_R";
        NetMsgEvent[NetMsgEvent["GAME_IS_OKS"] = 134] = "GAME_IS_OKS";
        NetMsgEvent[NetMsgEvent["GAME_IS_OKR"] = 135] = "GAME_IS_OKR";
    })(NetMsgEvent = network.NetMsgEvent || (network.NetMsgEvent = {}));
    var BattleMsgEvent = (function () {
        function BattleMsgEvent() {
        }
        //准备游戏
        BattleMsgEvent.GAME_READY = "GameReady";
        //叫地主结束
        BattleMsgEvent.CALL_LANDLORD_OVER = "CallLandLordOver";
        //下一个叫地主
        BattleMsgEvent.CALL_LANDLORD_NEXT = "CallLandLordNext";
        //出牌
        BattleMsgEvent.PLAYER_CARDS = "PlayerCards";
        //上报分数事件
        BattleMsgEvent.REPORT_DATA = "ReportData";
        //游戏结束
        BattleMsgEvent.GAME_OVER = "GameOver";
        // 进入房间，准备倒计时
        BattleMsgEvent.START_THE_COUNTDOWN = "START_THE_COUNTDOWN";
        // 回到游戏大厅
        BattleMsgEvent.GAME_IS_OK = "GAME_IS_OK";
        return BattleMsgEvent;
    }());
    network.BattleMsgEvent = BattleMsgEvent;
    __reflect(BattleMsgEvent.prototype, "network.BattleMsgEvent");
})(network || (network = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var Main = (function (_super) {
    __extends(Main, _super);
    function Main() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.topMask = new egret.Shape();
        return _this;
    }
    Main.prototype.createChildren = function () {
        _super.prototype.createChildren.call(this);
        //注入自定义的素材解析器
        var assetAdapter = new AssetAdapter();
        egret.registerImplementation("eui.IAssetAdapter", assetAdapter);
        egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());
        this.runGame().catch(function (e) {
            console.log(e);
        });
    };
    Main.prototype.runGame = function () {
        return __awaiter(this, void 0, void 0, function () {
            var rootView;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        Toast.initRes(this, "resource/loading/toast-bg.png");
                        rootView = new egret.Sprite();
                        rootView.width = this.stage.width;
                        rootView.height = this.stage.height;
                        rootView.x = 0;
                        rootView.y = 0;
                        this.addChild(rootView);
                        SceneManager.init(rootView);
                        egret.ImageLoader.crossOrigin = "anonymous";
                        return [4 /*yield*/, this.getWxUserInfo()];
                    case 1:
                        _a.sent();
                        // SceneManager.init(this);
                        return [4 /*yield*/, this.loadResource()];
                    case 2:
                        // SceneManager.init(this);
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    // /**
    //  * faceBook
    //  */
    // private initializeAsync(): void {
    //     FBInstant.initializeAsync().then(function () {
    //         egret.log("getLocale:", FBInstant.getLocale());
    //         egret.log("getPlatform:", FBInstant.getPlatform());
    //         egret.log("getSDKVersion", FBInstant.getSDKVersion());
    //         egret.log("getSupportedAPIs", FBInstant.getSupportedAPIs());
    //         egret.log("getEntryPointData", FBInstant.getEntryPointData());
    //     })
    //     setTimeout(function () {
    //         FBInstant.setLoadingProgress(100);
    //     }, 1000);
    //     this.initStartGameAsync();
    // }
    // /**
    //  * faceBook
    //  */
    // private initStartGameAsync() {
    //     FBInstant.startGameAsync().then(
    //         function () {
    //             // Retrieving context and player information can only be done
    //             // once startGameAsync() resolves
    //             var contextId = FBInstant.context.getID();
    //             var contextType = FBInstant.context.getType();
    //             var playerName = FBInstant.player.getName();
    //             var playerPic = FBInstant.player.getPhoto();
    //             var playerId = FBInstant.player.getID();
    //             // Once startGameAsync() resolves it also means the loading view has 
    //             // been removed and the user can see the game viewport
    //         }).catch(function (e) {
    //             console.log("startgame error", e)
    //         });
    // }
    /**
     * 获取微信头像，存储起来
     */
    Main.prototype.getWxUserInfo = function () {
        try {
            getWxUserInfo(function callback(userinfo) {
                egret.log("main", userinfo);
                var data;
                GlobalData.myUser.nickName = userinfo.nickName;
                GlobalData.myUser.avator = userinfo.avatarUrl;
                //todo 
                PokeMatchvsEngine.getInstance.hashGet("integral");
            });
        }
        catch (e) {
            egret.log("错误", e.message);
        }
    };
    Main.prototype.loadResource = function () {
        return __awaiter(this, void 0, void 0, function () {
            var loadingView, e_1;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        _a.trys.push([0, 4, , 5]);
                        loadingView = new LoadingUI();
                        this.stage.addChild(loadingView);
                        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_INIT, this.onEvent, this);
                        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_REGISTERUSER, this.onEvent, this);
                        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_LOGIN, this.onEvent, this);
                        //初始化
                        return [4 /*yield*/, RES.loadConfig("resource/default.res.json", "resource/")];
                    case 1:
                        //初始化
                        _a.sent();
                        return [4 /*yield*/, this.loadTheme()];
                    case 2:
                        _a.sent();
                        return [4 /*yield*/, RES.loadGroup("preload", 0, loadingView)];
                    case 3:
                        _a.sent();
                        this.stage.removeChild(loadingView);
                        this.createGameScene();
                        PokeMatchvsEngine.getInstance.init(MatchvsData.pChannel, MatchvsData.pPlatform, MatchvsData.gameID);
                        return [3 /*break*/, 5];
                    case 4:
                        e_1 = _a.sent();
                        console.error(e_1);
                        return [3 /*break*/, 5];
                    case 5: return [2 /*return*/];
                }
            });
        });
    };
    Main.prototype.loadTheme = function () {
        var _this = this;
        return new Promise(function (resolve, reject) {
            // load skin theme configuration file, you can manually modify the file. And replace the default skin.
            //加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。
            var theme = new eui.Theme("resource/default.thm.json", _this.stage);
            theme.addEventListener(eui.UIEvent.COMPLETE, function () {
                resolve();
            }, _this);
        });
    };
    Main.prototype.onEvent = function (e) {
        egret.log(e);
        switch (e.type) {
            case MatchvsMessage.MATCHVS_INIT:
                PokeMatchvsEngine.getInstance.registerUser();
                // }
                break;
            //注册
            case MatchvsMessage.MATCHVS_REGISTERUSER:
                // this.userID = e.data.id;
                this.userInfoStore(e.data);
                break;
            case MatchvsMessage.MATCHVS_LOGIN:
                if (e.data.status == 200) {
                    Toast.show("登录成功");
                    MatchvsData.loginStatus = true;
                    this.timer = new egret.Timer(1000, 1);
                    this.timer.addEventListener(egret.TimerEvent.TIMER, this.wxInvite, this);
                    this.timer.start();
                }
                else {
                    Toast.show("登录失败");
                }
                break;
            case MatchvsMessage.MATCHVS_JOINROOM_RSP:
                this.removeEvent();
                var obj = { roomID: this.roomID, gameMode: MatchvsData.gameMode, isInvite: false, isRestart: true };
                MatchvsData.gameMode = true;
                SceneManager.showScene(Room, obj);
                break;
        }
    };
    Main.prototype.userInfoStore = function (userInfo) {
        /**
         * 微信头像与昵称的获取在注册之前，如果已经存在，就使用微信的，如果为"",就使用ID代替昵称，头像为随机；
         * 还需要存在本地
         */
        if (GlobalData.myUser.nickName == "") {
            GlobalData.myUser.nickName = userInfo.id;
        }
        if (GlobalData.myUser.avator == "") {
            GlobalData.myUser.avator = MatchvsData.defaultIcon[Math.round(10 * Math.random())];
        }
        GlobalData.myUser.userID = userInfo.id;
        GlobalData.myUser.token = userInfo.token;
        this.getUserPointValue(GlobalData.myUser.userID);
    };
    Main.prototype.createGameScene = function () {
        // this.removeEvent()
        SceneManager.showScene(Login);
    };
    /**
     * 根据name关键字创建一个Bitmap对象。name属性请参考resources/resource.json配置文件的内容。
     * Create a Bitmap object according to name keyword.As for the property of name please refer to the configuration file of resources/resource.json.
     */
    Main.prototype.createBitmapByName = function (name) {
        var result = new egret.Bitmap();
        var texture = RES.getRes(name);
        result.texture = texture;
        return result;
    };
    /**
     * 微信邀请
     */
    Main.prototype.wxInvite = function () {
        try {
            var LaunchOption = getLaunchOptionsSync();
            this.roomID = LaunchOption.query.roomID;
            if (this.roomID != null && this.roomID != "" && this.roomID != 0) {
                //昵称，头像，积分的顺序，用 /n 分割
                PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_JOINROOM_RSP, this.onEvent, this);
                PokeMatchvsEngine.getInstance.joinRoom(this.roomID, MatchvsData.getDefaultUserProfile());
            }
        }
        catch (err) {
            egret.log(err, err.message);
        }
    };
    /**
     * 在这里移除所有的监听
     */
    Main.prototype.removeEvent = function () {
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_LOGIN, this.onEvent, this);
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_INIT, this.onEvent, this);
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_REGISTERUSER, this.onEvent, this);
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_JOINROOM_RSP, this.onEvent, this);
    };
    Main.prototype.getUserPointValue = function (userID) {
        var keyList = JSON.stringify([{ "key": userID }]);
        var params = "gameID=" + MatchvsData.gameID + "&userID=" + userID + "&keyList=" + keyList;
        var matchvsMD5 = new MD5();
        var sign = matchvsMD5.hex_md5(MatchvsData.appKey + "&gameID=" + MatchvsData.gameID + "&userID=" + userID + "&" + MatchvsData.secret);
        var rankListUrl = MatchvsData.alphaHttpUrl + params + "&sign=" + sign;
        var http = new MatchvsHttp({
            onMsg: function (buf) {
                egret.log("玩家信息拿到了", buf);
                var buf = JSON.parse(buf);
                if (buf.data.dataList.length < 1) {
                    egret.log("没有拿到数据");
                    GlobalData.myUser.pointValue = MatchvsData.defaultScore;
                }
                else {
                    egret.log("玩家分数是", buf.data.dataList[0].value);
                    GlobalData.myUser.pointValue = buf.data.dataList[0].value;
                }
            },
            onErr: function (errCode, errMsg) {
                egret.log("获取玩家错误信息", errMsg);
                // GlobalData.myUser.pointValue = ;
                return null;
            }
        });
        http.get(rankListUrl);
    };
    /**
     * 点击按钮
     * Click the button
     */
    Main.prototype.onButtonClick = function (e) {
        if (e.$currentTarget == this.topMask) {
        }
        var panel = new eui.Panel();
        panel.title = "Title";
        panel.horizontalCenter = 0;
        panel.verticalCenter = 0;
        this.addChild(panel);
    };
    return Main;
}(eui.UILayer));
__reflect(Main.prototype, "Main");
var DebugPlatform = (function () {
    function DebugPlatform() {
    }
    DebugPlatform.prototype.getUserInfo = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, { nickName: "username" }];
            });
        });
    };
    DebugPlatform.prototype.login = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    return DebugPlatform;
}());
__reflect(DebugPlatform.prototype, "DebugPlatform", ["Platform"]);
if (!window.platform) {
    window.platform = new DebugPlatform();
}
var SceneManager = (function () {
    function SceneManager() {
    }
    SceneManager.init = function (root) {
        this.root = root;
    };
    SceneManager.showScene = function (scene, par) {
        if (!this.root) {
            console.error("SceneManager not be init()");
            return;
        }
        if (!scene) {
            console.error("scene is null");
            return;
        }
        //hide top
        if (this.root.numChildren > 0) {
            var top = this.root.getChildAt(this.root.numChildren - 1);
            top.onHide && top.onHide();
        }
        //new  a scene
        scene = new scene(par);
        scene.name = scene.constructor.name;
        scene.onShow && scene.onShow(par);
        //show currentScene
        this.root.addChild(scene);
        if (SceneManager.isAnimation) {
            scene.x = 480;
            egret.Tween.get(scene, { loop: false }).to({ x: 0, y: 0 }, 300, egret.Ease.circInOut);
        }
        // }
        console.log("[SceneManager] show  scene:" + scene.constructor.name + "@" + scene.hashCode);
    };
    SceneManager.back = function () {
        if (this.root.numChildren > 0) {
            var perScene = this.root.getChildAt(this.root.numChildren - 1);
            if (perScene) {
                perScene.onHide && perScene.onHide();
                if (!SceneManager.isAnimation) {
                    if (this.root.numChildren > 1) {
                        var top = this.root.getChildAt(this.root.numChildren - 2);
                        console.log("[SceneManager]  Back,  from scene:" + perScene.constructor.name + "@" + perScene.hashCode + " to " + top.constructor.name + "@" + top.hashCode);
                        top.onShow && top.onShow();
                    }
                    this.root.removeChild(perScene);
                }
                else {
                    perScene.x = 0;
                    egret.Tween.get(perScene, { loop: false }).to({ x: 800, y: 0 }, 600, egret.Ease.quadIn).call(function () {
                        perScene.x = 0;
                        this.root.removeChild(perScene);
                    }.bind(this));
                    //show top
                    if (this.root.numChildren > 1) {
                        var top = this.root.getChildAt(this.root.numChildren - 2);
                        top.onShow && top.onShow();
                        top.x = -480;
                        egret.Tween.get(top, { loop: false }).to({ x: 0, y: 0 }, 400, egret.Ease.backIn);
                    }
                }
                return true;
            }
            else {
                console.warn('[WARN] preScene is undefine');
                return false;
            }
        }
        else {
            console.warn("[SceneManager] Do`t Back!");
            return false;
        }
    };
    SceneManager.JumpResultUI = function (p3, p1, p2, iswin, islandwin, timestr, roomid) {
        SceneManager.root.removeChildren();
        var re = new ResultUI();
        SceneManager.root.addChild(re);
        if (p1.isLandLord) {
            re.showResult(p1, p2, p3, iswin, islandwin, timestr, roomid);
        }
        else if (p2.isLandLord) {
            re.showResult(p2, p1, p3, iswin, islandwin, timestr, roomid);
        }
        else if (p3.isLandLord) {
            re.showResult(p3, p1, p2, iswin, islandwin, timestr, roomid);
        }
    };
    SceneManager.ErrorPage = function (msg, callFun, obj) {
        SceneManager.root.removeChildren();
        var errpage = new ErrorNote();
        errpage.SetErrorMsg(msg, callFun);
        SceneManager.root.addChild(errpage);
    };
    SceneManager.isAnimation = false;
    SceneManager.sceneStack = [];
    return SceneManager;
}());
__reflect(SceneManager.prototype, "SceneManager");
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var ThemeAdapter = (function () {
    function ThemeAdapter() {
    }
    /**
     * 解析主题
     * @param url 待解析的主题url
     * @param onSuccess 解析完成回调函数，示例：compFunc(e:egret.Event):void;
     * @param onError 解析失败回调函数，示例：errorFunc():void;
     * @param thisObject 回调的this引用
     */
    ThemeAdapter.prototype.getTheme = function (url, onSuccess, onError, thisObject) {
        function onResGet(e) {
            onSuccess.call(thisObject, e);
        }
        function onResError(e) {
            if (e.resItem.url == url) {
                RES.removeEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, onResError, null);
                onError.call(thisObject);
            }
        }
        if (typeof generateEUI !== 'undefined') {
            egret.callLater(function () {
                onSuccess.call(thisObject, generateEUI);
            }, this);
        }
        else {
            RES.addEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, onResError, null);
            RES.getResByUrl(url, onResGet, this, RES.ResourceItem.TYPE_TEXT);
        }
    };
    return ThemeAdapter;
}());
__reflect(ThemeAdapter.prototype, "ThemeAdapter", ["eui.IThemeAdapter"]);
var GlobalData = (function () {
    function GlobalData() {
    }
    GlobalData.myUser = new GUser;
    GlobalData.baseVaue = 1; //打完一局 基本计算分数
    GlobalData.ReportModel = 1; //上报分数模式，1 直接替换，2 - 累加
    return GlobalData;
}());
__reflect(GlobalData.prototype, "GlobalData");
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var AssetAdapter = (function () {
    function AssetAdapter() {
    }
    /**
     * @language zh_CN
     * 解析素材
     * @param source 待解析的新素材标识符
     * @param compFunc 解析完成回调函数，示例：callBack(content:any,source:string):void;
     * @param thisObject callBack的 this 引用
     */
    AssetAdapter.prototype.getAsset = function (source, compFunc, thisObject) {
        function onGetRes(data) {
            compFunc.call(thisObject, data, source);
        }
        if (RES.hasRes(source)) {
            var data = RES.getRes(source);
            if (data) {
                onGetRes(data);
            }
            else {
                RES.getResAsync(source, onGetRes, this);
            }
        }
        else {
            RES.getResByUrl(source, onGetRes, this, RES.ResourceItem.TYPE_IMAGE);
        }
    };
    return AssetAdapter;
}());
__reflect(AssetAdapter.prototype, "AssetAdapter", ["eui.IAssetAdapter"]);
/**
 * 控制卡牌显示等规则
 * Created by Administrator on 2015/12/19.
 */
var battle;
(function (battle) {
    //import ChatInst = windowui.ChatInst;
    var BattleBtnControl = (function (_super) {
        __extends(BattleBtnControl, _super);
        function BattleBtnControl() {
            var _this = _super.call(this) || this;
            _this._state = 0;
            _this._gameScene = null;
            _this._setting = null;
            _this._autoing = null;
            _this._exiting = null;
            //private _talking: BattleBtnUI = null;
            //private _prompt: BattleBtnUI = null;
            //private _prompTips:egret.Bitmap=null;
            _this._ready = null;
            _this._callNo = null;
            _this._call1 = null;
            _this._call2 = null;
            _this._call3 = null;
            _this._sendNo = null;
            _this._sendReset = null;
            _this._sendPromt = null;
            _this._sendCard = null;
            _this._currentDownSprite = null; //当前拖动容器
            _this._callSprite = null; //叫分按钮容器;
            _this._playSprite = null; //玩游戏按钮
            _this._readySprite = null; //准备按钮
            _this._touchStart = null;
            _this._objStart = null;
            _this._myCardProxy = null;
            return _this;
        }
        Object.defineProperty(BattleBtnControl.prototype, "State", {
            get: function () {
                return this._state;
            },
            enumerable: true,
            configurable: true
        });
        BattleBtnControl.prototype.SetCardProxy = function (mcp) {
            this._myCardProxy = mcp;
        };
        BattleBtnControl.prototype.Init = function (gs) {
            this._gameScene = gs;
            /**
             * btn_setting 设置按钮
             */
            this._setting = new battle.BattleBtnUI("btn_setting");
            //LayerMgr.TopUI.addChild(this._setting);
            this._setting.x = 338;
            this._setting.y = 17;
            /**
             * btn_roomauto
             */
            this._autoing = new battle.BattleBtnUI("btn_roomauto");
            //LayerMgr.TopUI.addChild(this._autoing);
            this._autoing.x = 517;
            this._autoing.y = 17;
            /**
             * btn_roomout 退出房间按钮
             */
            this._exiting = new battle.BattleBtnUI("btn_roomout");
            //LayerMgr.TopUI.addChild(this._exiting);
            this._exiting.x = 583;
            this._exiting.y = 17;
            /**
             * btn_chat
             */
            // this._talking = new BattleBtnUI("ui_chat_btn");
            // this._gameScene.addChild(this._talking);
            // this._talking.x = 10;
            // this._talking.y = 1055;
            /**
             * robot
             */
            // this._prompt = new BattleBtnUI("ui_robot");
            // this._gameScene.addChild(this._prompt);
            // this._prompt.ClickScale = false;
            // this._prompt.x = 0;
            // this._prompt.y = 632;
            this.setBtnSprite();
            this._exiting.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this);
            //this._autoing.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this);
            this._setting.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this);
            //this._talking.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this);
            //this._prompt.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this);
            // 注册返回按键事件
            document.addEventListener("plusready", function () {
                // 注册返回按键事件
                window["plus"].key.addEventListener('backbutton', function () {
                    // 事件处理
                    window["plus"].nativeUI.confirm("退出程序？", function (event) {
                        if (event.index) {
                            window["plus"].runtime.quit();
                        }
                    }, null, ["取消", "确定"]);
                }, false);
            });
        };
        //设置托管
        // public SetPlayerAuto(tableid: number, isauto: boolean): void {
        //     if (tableid != 3) {
        //         return;
        //     }
        //     this._prompt.visible = isauto;
        //     this._prompt.touchEnabled = isauto;
        // }
        // 设置一些按钮样式
        //打牌
        BattleBtnControl.prototype.Playing = function (isnew) {
            this._state = BattleBtnControl.STATE_Playing;
            this._readySprite.visible = false;
            this._callSprite.visible = false;
            this._playSprite.visible = true; //iscanshow;
            this._sendNo.visible = true;
            this._sendCard.visible = true;
            // 不出
            this._sendNo.touchEnabled = true;
            this._sendNo.SetBit("btn_buchu");
            // 提示
            this._sendPromt.touchEnabled = true;
            this._sendPromt.SetBit("btn_tishi");
            // 出牌
            this._sendCard.touchEnabled = false;
            this._sendCard.SetBit("btn_chupai");
            // 不出牌,灰色按钮
            if (isnew) {
                this._sendNo.SetBit("btn_buchu_no");
                this._sendNo.touchEnabled = false;
            }
        };
        // 修改一些按钮可点击状态
        //可以出牌
        BattleBtnControl.prototype.PlayingShow = function (isshow) {
            if (isshow) {
                this._sendCard.SetBit("btn_chupai");
                this._sendCard.touchEnabled = true;
            }
            else {
                this._sendCard.SetBit("btn_chupai_no");
                this._sendCard.touchEnabled = false;
            }
        };
        //叫地主
        BattleBtnControl.prototype.CallLandOwner = function (nowscore) {
            this._state = BattleBtnControl.STATE_Qiangdizhu;
            this._readySprite.visible = false;
            this._callSprite.visible = true;
            this._playSprite.visible = false;
            this._call1.touchEnabled = true;
            this._call2.touchEnabled = true;
            this._call3.touchEnabled = true;
            this._callNo.touchEnabled = true;
            this._call1.alpha = 1;
            this._call2.alpha = 1;
            this._call3.alpha = 1;
            this._callNo.alpha = 1;
            if (nowscore == 1) {
                this._call1.touchEnabled = false;
                this._call1.alpha = 0.3;
            }
            else if (nowscore == 2) {
                this._call1.touchEnabled = false;
                this._call1.alpha = 0.3;
                this._call2.touchEnabled = false;
                this._call2.alpha = 0.3;
            }
        };
        //全部隐藏
        BattleBtnControl.prototype.HideAll = function () {
            this._state = BattleBtnControl.STATE_HideAll;
            this._readySprite.visible = false;
            this._callSprite.visible = false;
            this._playSprite.visible = false;
        };
        //进入房间
        BattleBtnControl.prototype.RoomIn = function () {
            this._state = BattleBtnControl.STATE_Ready;
            this._callSprite.visible = false;
            this._playSprite.visible = false;
            this._readySprite.visible = false;
            // if (SceneMgr.Instance.GetCurrentProxy() instanceof sceneproxy.GameSceneProxy) {
            //      //隐藏ready 按钮
            //     var dp: data.Player = (<sceneproxy.GameSceneProxy>(SceneMgr.Instance.GetCurrentProxy())).GetMainPlayer();
            //     if (dp && dp.IsReady) {
            //         this._readySprite.visible = false;
            //     }
            // }
        };
        BattleBtnControl.prototype.setBtnSprite = function () {
            this._callSprite = new egret.Sprite(); //叫分按钮容器;
            this._callSprite.touchChildren = true;
            this._callSprite.touchEnabled = true;
            this._callSprite.x = 0;
            this._callSprite.y = 550;
            this._playSprite = new egret.Sprite(); //玩游戏按钮
            this._playSprite.touchChildren = true;
            this._playSprite.touchEnabled = true;
            this._playSprite.x = 0;
            this._playSprite.y = 550;
            this._readySprite = new egret.Sprite(); //准备按钮this.//
            this._readySprite.touchChildren = true;
            this._readySprite.touchEnabled = true;
            this._readySprite.x = 255;
            this._readySprite.y = 650;
            this._gameScene.addChild(this._callSprite);
            this._gameScene.addChild(this._playSprite);
            this._gameScene.addChild(this._readySprite);
            this._readySprite.visible = false;
            this._callSprite.visible = false;
            this._playSprite.visible = false;
            this._ready = new battle.BattleBtnUI("btn_zhunbei", null, "");
            this._readySprite.addChild(this._ready);
            this._ready.SetTxt(40, 0xffffff);
            this._ready.x = 4; //0;//4;
            this._ready.y = 20; //0;//20;
            /**
             * 叫地主时的按钮分布
             */
            // 不叫0分
            this._callNo = new battle.BattleBtnUI("btn_bujiao", null, "");
            this._callSprite.addChild(this._callNo);
            this._callNo.x = 20;
            this._callNo.y = 0;
            // 1分
            this._call1 = new battle.BattleBtnUI("btn_yifen", null, "");
            this._callSprite.addChild(this._call1);
            this._call1.x = 224;
            this._call1.y = 0;
            // 2分
            this._call2 = new battle.BattleBtnUI("btn_erfen", null, "");
            this._callSprite.addChild(this._call2);
            this._call2.x = 360;
            this._call2.y = 0;
            // 3分
            this._call3 = new battle.BattleBtnUI("btn_sanfen", null, "");
            this._callSprite.addChild(this._call3);
            this._call3.x = 495;
            this._call3.y = 0;
            /**
             * 添加完游戏按钮，不要，重置，提示，出牌
             */
            this._sendNo = new battle.BattleBtnUI("btn_buchu", null, "");
            this._playSprite.addChild(this._sendNo);
            this._sendNo.x = 20;
            this._sendNo.y = 0;
            this._sendReset = new battle.BattleBtnUI("btn_chongxuan", null, "");
            this._playSprite.addChild(this._sendReset);
            this._sendReset.x = 224;
            this._sendReset.y = 0;
            this._sendPromt = new battle.BattleBtnUI("btn_tishi", null, "");
            this._playSprite.addChild(this._sendPromt);
            this._sendPromt.x = 360;
            this._sendPromt.y = 0;
            this._sendCard = new battle.BattleBtnUI("btn_chupai", null, "");
            this._playSprite.addChild(this._sendCard);
            this._sendCard.x = 495;
            this._sendCard.y = 0;
            this._sendReset.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this, false);
            this._sendCard.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this, false);
            this._sendPromt.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this, false);
            this._sendNo.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this, false);
            this._call3.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this, false);
            this._call2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this, false);
            this._call1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this, false);
            this._callNo.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this, false);
            this._ready.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this, false);
        };
        // 没有调用
        BattleBtnControl.prototype.onToouchBegin = function (e) {
            this._touchStart = new egret.Point();
            this._objStart = new egret.Point();
            this._touchStart.x = e.stageX;
            this._touchStart.y = e.stageY;
            this._objStart.x = e.currentTarget.x;
            this._objStart.y = e.currentTarget.y;
            this._currentDownSprite = e.currentTarget;
        };
        // 没有调用
        BattleBtnControl.prototype.onToouchMove = function (e) {
            if (e.currentTarget != this._currentDownSprite) {
                return;
            }
            var cx = e.stageX;
            var cy = e.stageY;
            var bx = cx - this._touchStart.x;
            var by = cy - this._touchStart.y;
            e.currentTarget.x = this._objStart.x + bx;
            e.currentTarget.y = this._objStart.y + by;
            if (e.currentTarget.x > 366) {
                e.currentTarget.x = 366;
            }
            if (e.currentTarget.x < 0) {
                e.currentTarget.x = 0;
            }
            if (e.currentTarget.y < 0) {
                e.currentTarget.y = 0;
            }
            if (e.currentTarget.y > (Config.StageHeight - e.currentTarget.height)) {
                e.currentTarget.y = (Config.StageHeight - e.currentTarget.height);
            }
            this._currentDownSprite.touchChildren = false;
        };
        // 没有调用
        BattleBtnControl.prototype.onToouchEnd = function (e) {
            if (e.currentTarget != this._currentDownSprite) {
                return;
            }
            var cx = e.stageX;
            var cy = e.stageY;
            var bx = cx - this._touchStart.x;
            var by = cy - this._touchStart.y;
            e.currentTarget.x = this._objStart.x + bx;
            e.currentTarget.y = this._objStart.y + by;
            this._touchStart = null;
            this._objStart = null;
            if (e.currentTarget.x > 366) {
                e.currentTarget.x = 366;
            }
            if (e.currentTarget.x < 0) {
                e.currentTarget.x = 0;
            }
            if (e.currentTarget.y < 0) {
                e.currentTarget.y = 0;
            }
            if (e.currentTarget.y > (Config.StageHeight - e.currentTarget.height)) {
                e.currentTarget.y = (Config.StageHeight - e.currentTarget.height);
            }
            this._currentDownSprite.touchChildren = true;
            this._currentDownSprite = null;
        };
        BattleBtnControl.prototype.onTap = function (e) {
            // if (e.currentTarget == this._setting) {
            //     windowui.SettingInst.Instance.Show();
            // }
            // if (e.currentTarget == this._autoing && this._prompt.visible == false) {
            //     NetMgr.Instance.SendMsg(enums.NetEnum.CLIENT_2_GAME_AUTO, { isauto: true });
            // }
            // if (e.currentTarget == this._prompt) {
            //     NetMgr.Instance.SendMsg(enums.NetEnum.CLIENT_2_GAME_AUTO, { isauto: false });
            // }
            // else if (e.currentTarget == this._talking) {
            //     windowui.ChatInst.Instance.Show();
            // }
            if (e.currentTarget == this._exiting) {
                //network.BattleMsg.getInstance().sendToPlayers(enums.NetEnum.CLIENT_2_GAME_REQ_EXIT, {});
            }
            else if (e.currentTarget == this._ready) {
                //network.BattleMsg.getInstance().sendToPlayers(enums.NetEnum.CLIENT_2_GAME_READY, {});
            }
            else if (e.currentTarget == this._sendCard) {
                var cardArr = this._myCardProxy.GetWillShowList();
                if (cardArr == null) {
                    console.info("牌类型出错");
                    return;
                }
                //this.dispatchEvent(new egret.Event(BattleBtnControl.PLAY_CARD_EVENT, false, false,  { cardlist: cardArr }));
                network.BattleMsg.getInstance().sendToGameServer(network.NetMsgEvent.PLAY_CARDS_S, { cardlist: cardArr });
            }
            else if (e.currentTarget == this._sendPromt) {
                //NetMgr.Instance.SendMsg(enums.NetEnum.CLIENT_2_GAME_READY,{});
                var hasbigger = this._myCardProxy.getHasBigger();
                if (!hasbigger) {
                    network.BattleMsg.getInstance().sendToGameServer(network.NetMsgEvent.PLAY_CARDS_S, { cardlist: [] });
                }
                else {
                    var hascar = this._myCardProxy.Prompt(false, true);
                    this._myCardProxy.SetBtnVisible();
                }
            }
            else if (e.currentTarget == this._sendReset) {
                this._myCardProxy.Reset();
            }
            else if (e.currentTarget == this._sendNo) {
                network.BattleMsg.getInstance().sendToGameServer(network.NetMsgEvent.PLAY_CARDS_S, { cardlist: [] });
            }
            else if (e.currentTarget == this._call3) {
                this.HideAll();
                network.BattleMsg.getInstance().sendToGameServer(network.NetMsgEvent.CALL_LAND_S, { score: 3 });
                console.log("叫地主 _call3");
            }
            else if (e.currentTarget == this._call2) {
                this.HideAll();
                network.BattleMsg.getInstance().sendToGameServer(network.NetMsgEvent.CALL_LAND_S, { score: 2 });
                console.log("叫地主_call2");
            }
            else if (e.currentTarget == this._call1) {
                this.HideAll();
                network.BattleMsg.getInstance().sendToGameServer(network.NetMsgEvent.CALL_LAND_S, { score: 1 });
                console.log("叫地主 _call1");
            }
            else if (e.currentTarget == this._callNo) {
                this.HideAll();
                network.BattleMsg.getInstance().sendToGameServer(network.NetMsgEvent.CALL_LAND_S, { score: 0 });
                console.log("叫地主 _callNo");
            }
        };
        BattleBtnControl.prototype.Release = function () {
            this._gameScene.removeChildren();
            this._gameScene = null;
        };
        BattleBtnControl.STATE_HideAll = 0;
        BattleBtnControl.STATE_Qiangdizhu = 1;
        BattleBtnControl.STATE_Playing = 2;
        BattleBtnControl.STATE_Ready = 3;
        BattleBtnControl.PLAY_CARD_EVENT = "PLAY_CARD_EVENT";
        return BattleBtnControl;
    }(egret.EventDispatcher));
    battle.BattleBtnControl = BattleBtnControl;
    __reflect(BattleBtnControl.prototype, "battle.BattleBtnControl");
})(battle || (battle = {}));
/**
 *
 * @author
 *
 */
var battle;
(function (battle) {
    var BattleBtnUI = (function (_super) {
        __extends(BattleBtnUI, _super);
        function BattleBtnUI(downurl, upurl, downtxt) {
            if (upurl === void 0) { upurl = null; }
            if (downtxt === void 0) { downtxt = null; }
            var _this = _super.call(this) || this;
            _this._clickScale = true;
            _this._downSp = null;
            _this._downimg = null;
            _this._grayimg = null;
            _this._txt = null;
            _this._downScale = 0.9;
            _this._offsetX = 0; //缩放左
            _this._offsetY = 0; //缩放上
            _this._bitTxt = null;
            _this._downSp = new egret.Sprite();
            _this._downimg = new egret.Bitmap(RES.getRes(downurl));
            _this._grayimg = new egret.Bitmap(RES.getRes(upurl));
            _this.addChild(_this._downSp);
            _this._downSp.addChild(_this._downimg);
            _this._downSp.addChild(_this._grayimg);
            _this._offsetX = _this._downimg.width * (1 - _this._downScale) / 2;
            _this._offsetY = _this._downimg.height * (1 - _this._downScale) / 2;
            _this.touchChildren = false;
            _this.touchEnabled = true;
            _this._grayimg.visible = false;
            var rt = RES.getRes(downtxt);
            if (rt == null) {
                _this._txt = new egret.TextField();
                _this._txt.text = downtxt;
                _this._txt.textColor = 0xffffff;
                _this.addChild(_this._txt);
                _this._txt.width = _this._downSp.width;
                _this._txt.textAlign = egret.HorizontalAlign.CENTER;
                _this._txt.x = (_this._downSp.width - _this._txt.width) / 2;
                _this._txt.y = (_this._downSp.height - _this._txt.height) / 2;
            }
            _this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, _this.onBegin, _this);
            _this.addEventListener(egret.TouchEvent.TOUCH_END, _this.onEnd, _this);
            _this.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, _this.onEnd, _this);
            return _this;
        }
        BattleBtnUI.prototype.SetWidthHeight = function (w, h) {
            this._downSp.width = w;
            this._downSp.height = h;
            this._grayimg.width = w;
            this._grayimg.height = h;
            this._txt.width = this._downSp.width;
            this._txt.y = (this._downSp.height - this._txt.height) / 2;
        };
        Object.defineProperty(BattleBtnUI.prototype, "ClickScale", {
            set: function (b) {
                this._clickScale = b;
            },
            enumerable: true,
            configurable: true
        });
        BattleBtnUI.prototype.ChangeTxt = function (str) {
            this._txt.text = str;
            this._txt.x = (this._downSp.width - this._txt.width) / 2;
            this._txt.y = (this._downSp.height - this._txt.height) / 2;
        };
        BattleBtnUI.prototype.SetBitTxt = function (str) {
            if (this._bitTxt == null) {
                this._bitTxt = new egret.BitmapText();
                this._bitTxt.font = RES.getRes("timefont_fnt");
                this._bitTxt.scaleX = this._bitTxt.scaleY = 0.5;
                this._downSp.addChild(this._bitTxt);
            }
            this._bitTxt.text = str;
            this._bitTxt.x = this._downSp.width - this._bitTxt.textWidth * 0.5 - 15;
            this._bitTxt.y = this._downSp.height - this._bitTxt.textHeight * 0.5 - 10;
        };
        BattleBtnUI.prototype.SetBit = function (downurl, upurl) {
            if (upurl === void 0) { upurl = null; }
            this._downimg.texture = RES.getRes(downurl);
            this._grayimg.texture = RES.getRes(upurl);
        };
        BattleBtnUI.prototype.SetTxt = function (size, color, width, tx, ty) {
            if (size === void 0) { size = 30; }
            if (color === void 0) { color = 0xffffff; }
            if (width === void 0) { width = null; }
            if (tx === void 0) { tx = null; }
            if (ty === void 0) { ty = null; }
            this._txt.size = size;
            this._txt.textColor = color;
            if (width) {
                this._txt.width = width;
            }
            this._txt.x = (this._downSp.width - this._txt.width) / 2;
            this._txt.y = (this._downSp.height - this._txt.height) / 2;
        };
        BattleBtnUI.prototype.onBegin = function (e) {
            if (this._clickScale) {
                this._downSp.scaleX = this._downSp.scaleY = this._downScale;
                this._grayimg.scaleX = this._grayimg.scaleY = this._downScale;
                this._downSp.x += this._offsetX;
                this._downSp.y += this._offsetY;
                this._grayimg.x += this._offsetX;
                this._grayimg.y += this._offsetY;
            }
            // SoundMgr.Instance.PlayEffect("btn_click_mp3");
        };
        BattleBtnUI.prototype.onEnd = function (e) {
            this._downSp.scaleX = this._downSp.scaleY = 1;
            this._grayimg.scaleX = this._grayimg.scaleY = this._downScale;
            this._downSp.x = 0;
            this._downSp.y = 0;
            this._grayimg.x = 0;
            this._grayimg.y = 0;
        };
        BattleBtnUI.prototype.init = function () {
        };
        return BattleBtnUI;
    }(egret.Sprite));
    battle.BattleBtnUI = BattleBtnUI;
    __reflect(BattleBtnUI.prototype, "battle.BattleBtnUI");
})(battle || (battle = {}));
var battle;
(function (battle) {
    var BattleStageControl = (function (_super) {
        __extends(BattleStageControl, _super);
        function BattleStageControl(stage) {
            var _this = _super.call(this) || this;
            _this._playerList = new Array(); //用户列表
            _this._myOwner = new battle.Player(); //我自己
            _this._landLordUser = null; //地主玩家
            _this._lastSendCardPlayer = null; //最后出牌玩家
            _this._callLandLordUID = 0; //叫地主的人的ID
            _this._landLordCardList = []; //底牌列表
            _this._tableCardList = []; //桌面大牌
            _this._playerPoint = 0; //用户指针,指向当前用户,对应玩家seatNo
            _this._tablelistdata = null; //当前桌面上的牌
            _this._timesScore = "";
            _this._timesCount = 0; //加倍数
            _this._playCardType = null; //判断牌类型
            _this._compare = null; //比较牌
            _this._prompt = null; //提示牌
            _this._stage = null;
            _this._playerHeader_left = null; //上家
            _this._playerHeader_right = null; //下家
            _this._playerTimer = null; //闹钟提示
            _this._timeoutList = [];
            _this._stage = stage;
            return _this;
        }
        BattleStageControl.prototype.init = function () {
            //添加监听消息
            this.BattleEventListen();
            this._playerHeader_left = new battle.PlayerHead(); //上家
            this._playerHeader_right = new battle.PlayerHead(); //下家
            this._playerTimer = new battle.PlayerTime();
            this._playerTimer.Init();
            this._stage._playerTimerSprite.addChild(this._playerTimer);
            this._playerTimer.visible = false;
        };
        BattleStageControl.prototype.startGame = function () {
            this._playCardType = new gameLogic.PlayCardTypes(); //判断牌类型
            this._compare = new gameLogic.Compare(); //比较牌
            this._prompt = new gameLogic.Prompt(); //提示牌
            this.sendReadMsg(); //发送准备消息
        };
        Object.defineProperty(BattleStageControl.prototype, "landLordCardList", {
            //设置底牌
            set: function (arr) {
                this._landLordCardList = arr;
            },
            enumerable: true,
            configurable: true
        });
        /**
         * 添加用户
         * @param {GUser} user
         */
        BattleStageControl.prototype.addPlayer = function (user) {
            console.log("addPlayers", user);
            if (user) {
                var player = new battle.Player();
                player.avator = user.avator;
                player.nickName = user.nickName;
                player.userID = user.userID;
                player.pointValue = user.pointValue;
                player.rank = user.rank;
                this._playerList.push(player);
                if (player.userID == GlobalData.myUser.userID) {
                    this._myOwner = player;
                }
            }
        };
        //添加事件监听
        BattleStageControl.prototype.BattleEventListen = function () {
            //network.BattleMsg.getInstance() 是事件发送者，准备游戏发送回调
            network.BattleMsg.getInstance().addEventListener(network.BattleMsgEvent.GAME_READY, this.GameReadyEventCall, this);
            //叫地主结束
            network.BattleMsg.getInstance().addEventListener(network.BattleMsgEvent.CALL_LANDLORD_OVER, this.CallLandLordOver, this);
            //下一个叫地主
            network.BattleMsg.getInstance().addEventListener(network.BattleMsgEvent.CALL_LANDLORD_NEXT, this.CallLandLordNext, this);
            //收到出牌消息
            network.BattleMsg.getInstance().addEventListener(network.BattleMsgEvent.PLAYER_CARDS, this.PlayCards, this);
            //游戏结束
            network.BattleMsg.getInstance().addEventListener(network.BattleMsgEvent.GAME_OVER, this.GameOver, this);
            PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_LEVAE_ROOM_NOTIFY, this.leaveRoomNotify, this);
        };
        /**
         * 分配上下家
         */
        BattleStageControl.prototype.leftOrRight = function () {
            var _this = this;
            var myUser = this._myOwner;
            this._playerList.forEach(function (element) {
                //分配上下家
                if (element.userID == myUser.userID) {
                    element.LocalTableId = 3;
                }
                else {
                    console.info("leftOrRight ", myUser.seatNo, element.seatNo);
                    if (myUser.seatNo == 1) {
                        if (element.seatNo == 0) {
                            element.LocalTableId = 1;
                        }
                        else if (element.seatNo == 2) {
                            element.LocalTableId = 2;
                        }
                    }
                    else if (myUser.seatNo == 2) {
                        if (element.seatNo == 1) {
                            element.LocalTableId = 1;
                        }
                        else if (element.seatNo == 0) {
                            element.LocalTableId = 2;
                        }
                    }
                    else if (myUser.seatNo == 0) {
                        if (element.seatNo == 2) {
                            element.LocalTableId = 1;
                        }
                        else if (element.seatNo == 1) {
                            element.LocalTableId = 2;
                        }
                    }
                }
                console.info("leftOrRight", element.LocalTableId);
                //显示用户头像
                _this.SetPlayerHead(element, true);
            });
        };
        /**
         * 设置牌列表
         */
        BattleStageControl.prototype.setCardList = function (list) {
            var TableId = 1;
            var myUser = this._myOwner;
            var _loop_1 = function (i) {
                //获取牌列表
                this_1._playerList.forEach(function (element) {
                    console.info("list[i].userID == element.userID", list[i].userID, element.userID);
                    if (list[i].userID == element.userID) {
                        console.info("setCardList", list[i].card);
                        element.AddcardList(list[i].card);
                        element.seatNo = i;
                        element.IsReady = true;
                        console.info("element.seatNo" + element.seatNo);
                    }
                    // element.seatNo = i;
                });
            };
            var this_1 = this;
            //let seatNo = 0;
            for (var i = 0; i < list.length; i++) {
                _loop_1(i);
            }
            //用户列表安装 seatNo排序
            this._playerList.sort(function (a, b) {
                return a.seatNo < b.seatNo ? 1 : -1;
            });
            this.leftOrRight();
        };
        BattleStageControl.prototype.ReSendCard = function () {
            this._stage.ReSendCards();
            this._playerList.forEach(function (value) {
                value.clearPlayer();
            });
        };
        /**
         * 准备游戏后, 收到发牌消息调用这个函数，给各个用户填写牌信息
         */
        BattleStageControl.prototype.GameReadyEventCall = function (event) {
            this.removeEventListener(network.BattleMsgEvent.GAME_READY, this.GameReadyEventCall, this);
            this.ReSendCard();
            this._stage.WaitSendCardHide();
            console.info("GameReadyEventCall", event.data);
            var data = event.data;
            if (!data) {
                return;
            }
            //获取地主牌
            if ("lanownList" in data) {
                this._landLordCardList = data.lanownList;
            }
            if ("callOwner" in data) {
                this._callLandLordUID = data.callOwner;
            }
            if ("userCards" in data) {
                //获取洗出的牌进设置到用户列表中
                this.setCardList(data.userCards);
            }
            this._timeoutList.push(egret.setTimeout(this.beginCallLandLord, this, 4000));
            this.SendCard();
        };
        /**
         * 开始叫地主
         */
        BattleStageControl.prototype.beginCallLandLord = function () {
            var _this = this;
            console.info("beginCallLandLord:");
            var ismeCall = false;
            if (this._callLandLordUID == this._myOwner.userID) {
                ismeCall = true;
            }
            this._playerList.forEach(function (value) {
                if (value.userID == _this._callLandLordUID) {
                    console.info("beginCallLandLord", value);
                    //显示叫地主
                    _this._stage.ShowCallLand(value, ismeCall, 0, BattleStageControl.Delay_CallLand);
                }
            });
        };
        /**
         * 游戏结束的时候调用
         */
        BattleStageControl.prototype.GameOver = function (event) {
            network.BattleMsg.getInstance().removeEventListener(network.BattleMsgEvent.GAME_OVER, this.GameOver, this);
            console.info("游戏结束", event.data);
            if (!("winerID" in event.data) || !("winSeatNo" in event.data) || !("islandwin" in event.data)) {
                console.error("消息格式错误");
                return;
            }
            this._playerPoint = 0; //用户指针,指向当前用户,对应玩家tableid
            this._tablelistdata = null; //当前桌面上的牌
            this._landLordUser = null; //地主
            this._landLordCardList = []; //起始的三张地主牌
            //取消定时
            while (this._timeoutList.length > 0) {
                egret.clearTimeout(this._timeoutList.pop());
            }
            if (this["_playerHeader_left"]) {
                this["_playerHeader_left"].Ready = false;
                this["_playerHeader_left"].ShowCard = false;
            }
            if (this["_playerHeader_right"]) {
                this["_playerHeader_right"].Ready = false;
                this["_playerHeader_right"].ShowCard = false;
            }
            // this._playerTimer.visible = false;
            var islandwin = event.data.islandwin;
            var iswin = this._myOwner.isLandLord == islandwin;
            var tp1 = this.getPlayerByLocalTableId(1); //需要根据上下家区分显示牌
            var tp2 = this.getPlayerByLocalTableId(2);
            var tp3 = this.getPlayerByLocalTableId(3);
            var winplayer = this.getPlayerForUserID(event.data.winerID);
            this._stage.GameOver(iswin, tp1, tp2, tp3, islandwin, this._timesCount, false, 0, 0, 0, winplayer);
            this._stage = null;
        };
        /**
         * CallLandOver 结束叫地主
         */
        BattleStageControl.prototype.CallLandLordOver = function (evt) {
            console.log("叫地主结束", evt.data);
            if (!evt.data) {
                return;
            }
            if ("landOwner" in evt.data && "landCards" in evt.data && "value" in evt.data) {
                var landOwnerID = evt.data.landOwner;
                //获取底牌
                this.landLordCardList = evt.data.landCards;
                for (var i = 0; i < this._playerList.length; i++) {
                    //判断是不是地主
                    if (landOwnerID == this._playerList[i].userID) {
                        //this._landLordUser = new Player();
                        this._playerList[i].isLandLord = true;
                        this._playerList[i].landlordScore = evt.data.value;
                        this._playerList[i].AddcardList(evt.data.landCards); //添加地主牌
                        //获取地主
                        this._landLordUser = this._playerList[i];
                        this._timesScore = evt.data.value + "X" + 1;
                    }
                }
                // if(landOwnerID == this._myOwner.userID){
                // 	//如果地主是我就给我添加地主牌
                // 	this._myOwner.AddcardList(evt.data.landCards);
                // }
                this._tableCardList = [];
                this._playerPoint = this._landLordUser.seatNo;
                this._stage.OverCallLand(this._landLordUser, evt.data.landCards, this._myOwner, this._timesScore);
                this._stage.TurnPlayCard(this._landLordUser, (this._landLordUser.userID == this._myOwner.userID), true, this._tableCardList, BattleStageControl.Delay_ShowCard, false);
            }
        };
        /**
         * 下一个叫地主的人
         */
        BattleStageControl.prototype.CallLandLordNext = function (event) {
            var _this = this;
            var ismeCall = false;
            if (event.data.nextUser == this._myOwner.userID) {
                ismeCall = true;
            }
            this._callLandLordUID = event.data.nextUser;
            this._playerList.forEach(function (value) {
                if (value.userID == event.data.nextUser) {
                    console.info("beginCallLandLord", value);
                    //显示叫地主
                    _this._stage.ShowCallLand(value, ismeCall, event.data.score, BattleStageControl.Delay_CallLand);
                }
            });
        };
        /**
         * UserID 获取player
         */
        BattleStageControl.prototype.getPlayerForUserID = function (userID) {
            var player = null;
            this._playerList.forEach(function (value) {
                if (value.userID == userID) {
                    player = value;
                }
            });
            return player;
        };
        /**
         * seatNo获取player
         */
        BattleStageControl.prototype.getPlayerForSeatNo = function (seatNo) {
            var player = null;
            for (var i = 0; i < this._playerList.length; i++) {
                if (this._playerList[i].seatNo == seatNo) {
                    player = this._playerList[i];
                    console.info("getPlayerForSeatNo ", this._playerList[i]);
                    return this._playerList[i];
                }
            }
            return player;
        };
        BattleStageControl.prototype.getPlayerByLocalTableId = function (localTableID) {
            var player = null;
            this._playerList.forEach(function (value) {
                console.info("getPlayerByLocalTableId " + value.LocalTableId);
                if (value.LocalTableId == localTableID) {
                    player = value;
                }
            });
            return player;
        };
        /**
         * 获取下一个出牌的人
         */
        BattleStageControl.prototype.getNextPlayerPoint = function (playPonit) {
            this._playerPoint = playPonit;
            if ((++this._playerPoint) >= 3) {
                this._playerPoint = 0;
            }
            return this.getPlayerForSeatNo(this._playerPoint);
        };
        /**
         * 获取敌人
         */
        BattleStageControl.prototype.getPlayerEnemy = function (p) {
            var tableloc = 0;
            var pp = null;
            for (var i in this._playerList) {
                if (this._playerList[i] == null || this._playerList[i] == p) {
                    continue;
                }
                if (this._playerList[i].isLandLord != p.isLandLord && this._playerList[i].LocalTableId > tableloc) {
                    tableloc = this._playerList[i].LocalTableId;
                    pp = this._playerList[i];
                }
            }
            return pp;
        };
        /**
         * 获取敌人列表
         */
        BattleStageControl.prototype.getEnemy = function (p) {
            var len = this._playerList.length;
            var i = 0;
            var enelist = [];
            for (i = 0; i < len; i++) {
                if (this._playerList[i].userID != p.userID && this._playerList[i].isLandLord != p.isLandLord) {
                    enelist.push(this._playerList[i]);
                }
            }
            return enelist;
        };
        //过,要不起
        BattleStageControl.prototype.Pass = function (id) {
            if (this._landLordUser == null) {
                console.info("RobotGameMgr-Pass> 没有产生地主");
                return false;
            }
            if (this._playerPoint != id) {
                console.info("RobotGameMgr-Pass> 没有轮到该玩家");
                return false;
            }
            console.info("RobotGameMgr-Pass> 玩家pass,id:", id);
            this._playerPoint++;
            if (this._playerPoint >= 3) {
                this._playerPoint = 0;
            }
            if (this._tablelistdata && this._playerPoint == this._tablelistdata.FromId) {
                console.info("RobotGameMgr-Pass> 一轮结束 玩家可以重新出牌:", id);
                this._tablelistdata = null;
            }
            return true;
        };
        //出牌
        BattleStageControl.prototype.ShowCard = function (slist, id) {
            if (this._landLordUser == null) {
                console.info("RobotGameMgr-ShowCard> 没有产生地主,先叫分");
                return false;
            }
            if (this._playerPoint != id) {
                console.info("RobotGameMgr-ShowCard> 没有轮到该玩家");
                return false;
            }
            var cld = this._playCardType.GetType(slist);
            if (cld.Type == gameLogic.PlayCardTypes.Types_Error) {
                console.info("RobotGameMgr-ShowCard> 出牌不符合规则");
                return false;
            }
            var isbig = this._compare.IsBiger(cld, this._tablelistdata);
            if (!isbig) {
                console.info("RobotGameMgr-ShowCard> 出牌大不过桌面牌");
                return false;
            }
            if (cld.Type == gameLogic.PlayCardTypes.Types_Bomb) {
                this._timesCount++;
            }
            var player = this.getPlayerForSeatNo(this._playerPoint);
            console.info("_playerPoint", this._playerPoint);
            player.removeCards(slist);
            this._lastSendCardPlayer = player;
            console.info("该玩家剩余牌数量：" + player.cardNumber);
            if (player.cardNumber <= 0) {
                var enelist = this.getEnemy(player);
                var isspring = true;
                for (var i = 0; i < enelist.length; i++) {
                    if (enelist[i].cardNumber > 0) {
                        isspring = false;
                    }
                }
                if (isspring) {
                    this._timesCount++; //春天
                }
                player.cardList = slist; //显示最后玩家牌
                //this.GameOver();
                if (player.userID == this._myOwner.userID) {
                    console.info("发送游戏结束消息：", player.userID, this);
                    this.sendGameOver({
                        winSeatNo: player.seatNo,
                        islandwin: player.isLandLord,
                        timesCount: this._timesCount,
                    });
                }
                return false;
            }
            console.info("RobotGameMgr-ShowCard> 出牌成功");
            this._playerPoint++;
            if (this._playerPoint >= 3) {
                this._playerPoint = 0;
            }
            this._tablelistdata = cld;
            this._tablelistdata.FromId = id;
            return true;
        };
        /**
         * 收到出牌消息,显示牌
         */
        BattleStageControl.prototype.PlayCards = function (event) {
            console.info("出牌逻辑：", event.data);
            if (!("userID" in event.data) || !("cardlist" in event.data)) {
                return;
            }
            //显示上一个出牌的人的牌
            var player = this.getPlayerForUserID(event.data.userID);
            var clist = event.data.cardlist;
            var isok = false;
            if (clist == null || clist.length <= 0) {
                isok = this.Pass(this._playerPoint);
            }
            else {
                isok = this.ShowCard(clist, this._playerPoint);
            }
            if (isok == false) {
                //console.info("出牌失败");
                return;
            }
            var Crushed = 1;
            var isnew = this._tablelistdata == null; //是否出完一轮，新出牌
            //移除牌，玩家的牌
            player.removeCards(clist);
            console.info("myPlayer", this._myOwner, " sendCardPlayer:", player);
            //界面显示牌
            this._stage.ShowPlay(player, clist, (player.userID == this._myOwner.userID), "");
            if (this._tableCardList == null || this._tableCardList.length == 0) {
                var yasplayer = this.getPlayerEnemy(player);
                if (yasplayer) {
                    Crushed = yasplayer.LocalTableId;
                }
            }
            else {
                if (this._lastSendCardPlayer) {
                    Crushed = this._lastSendCardPlayer.LocalTableId;
                }
            }
            if (clist != null && clist.length > 0) {
                this._tableCardList = clist;
                this._lastSendCardPlayer = player;
            }
            //获取下一个出牌的人
            player = this.getNextPlayerPoint(player.seatNo);
            var canshowAll = false; //别人都剩一张的时候自己没有单牌,可以全下条件
            if (isnew) {
                this._tableCardList = [];
                this._lastSendCardPlayer = null;
            }
            console.info("新的一轮 isnew:", isnew);
            console.info("下一个出牌人 player:", player);
            console.info("当前桌上牌 _tableCardList:", this._tableCardList);
            //轮流出牌
            this._stage.TurnPlayCard(player, (player.userID == this._myOwner.userID), isnew, this._tableCardList, BattleStageControl.Delay_ShowCard, false);
        };
        /**
         * 启用发牌动画
         */
        BattleStageControl.prototype.SendCard = function () {
            // 发牌
            this._stage.SendCard(this._myOwner);
            this._playerHeader_left.ShowCard = true;
            this._playerHeader_left.Ready = false;
            this._playerHeader_right.ShowCard = true;
            this._playerHeader_right.Ready = false;
        };
        /**
         * 发送准备消息
         */
        BattleStageControl.prototype.sendReadMsg = function () {
            network.BattleMsg.getInstance().sendToGameServer(network.NetMsgEvent.GAME_READY_S, { value: "ready" });
        };
        /**
         * 发送游戏结束
         */
        BattleStageControl.prototype.sendGameOver = function (data) {
            network.BattleMsg.getInstance().sendToGameServer(network.NetMsgEvent.GAME_OVER_S, data);
        };
        /**
         * 显示对手玩家的头像
         */
        BattleStageControl.prototype.SetPlayerHead = function (p, isin) {
            if (isin === void 0) { isin = false; }
            if (p == null) {
                return;
            }
            //判断上下家 我
            if (p.userID == GlobalData.myUser.userID) {
                return;
            }
            var localid = "left";
            if (p.LocalTableId == 2) {
                localid = "right";
            }
            console.log("_playerHeader_", this["_playerHeader_" + localid]);
            this["_playerHeader_" + localid].Release();
            console.info("SetPlayerHead" + p.cardNumber);
            this["_playerHeader_" + localid].Init(p);
            this._stage._playerHeadSprite.addChildAt(this["_playerHeader_" + localid], 0);
            this["_playerHeader_" + localid].Ready = p.IsReady;
            this["_playerHeader_" + localid].UpdateCardNum();
            this["_playerHeader_" + localid].LandFlagVisible(false, false);
            if (p.LocalTableId == 1) {
                this._playerHeader_left.x = 65;
                this._playerHeader_left.y = 190;
            }
            else if (p.LocalTableId == 2) {
                this._playerHeader_right.x = 475;
                this._playerHeader_right.y = 190;
            }
            if (isin && p.LocalTableId != 3) {
                var ph = this["_playerHeader_" + localid];
                if (ph) {
                    egret.Tween.removeTweens(ph);
                    var tx = ph.x;
                    var fx = 0;
                    if (p.LocalTableId == 1) {
                        fx = tx - 300;
                    }
                    else if (p.LocalTableId == 2) {
                        fx = tx + 300;
                    }
                    ph.x = fx;
                    egret.Tween.get(ph).to({ x: tx }, 600);
                }
            }
        };
        BattleStageControl.prototype.SetPlayerTime = function (p, delaytime) {
            this._playerTimer.SetPoint(p.LocalTableId, delaytime);
            this._playerTimer.visible = true;
        };
        /**
         * 设置地主标志
         */
        BattleStageControl.prototype.SetPlayerLandFlag = function (landid) {
            if (this["_playerHeader_left"]) {
                this._playerHeader_left.IsLandOwner = false;
                this._playerHeader_left.LandFlagVisible(true, false);
            }
            if (this["_playerHeader_right"]) {
                this._playerHeader_right.IsLandOwner = false;
                this._playerHeader_right.LandFlagVisible(true, false);
            }
            if (landid == 1) {
                if (this["_playerHeader_left"]) {
                    this["_playerHeader_left"].IsLandOwner = false;
                    this["_playerHeader_left"].LandFlagVisible(true, true);
                }
            }
            else if (landid == 2) {
                if (this["_playerHeader_right"]) {
                    this["_playerHeader_right"].IsLandOwner = false;
                    this["_playerHeader_right"].LandFlagVisible(true, true);
                }
            }
        };
        /**
         * 更新牌数
         */
        BattleStageControl.prototype.UpdateAllCardNum = function () {
            if (this["_playerHeader_left"]) {
                this._playerHeader_left.ShowCard = true;
                this._playerHeader_left.UpdateCardNum();
            }
            if (this["_playerHeader_right"]) {
                this._playerHeader_right.ShowCard = true;
                this._playerHeader_right.UpdateCardNum();
            }
        };
        //有玩家离开房间就提示玩家离开房间，需要回到大厅。
        BattleStageControl.prototype.leaveRoomNotify = function (event) {
            PokeMatchvsEngine.getInstance.leaveRoom("他们都不玩了，我也离开");
            SceneManager.ErrorPage("玩家" + event.data.userId + "离开房间，请返回到大厅...", function () {
                SceneManager.showScene(Game);
            }, this);
        };
        BattleStageControl.prototype.Release = function () {
            console.info("BattleStageControl Release ");
            //network.BattleMsg.getInstance() 是事件发送者，准备游戏发送回调
            network.BattleMsg.getInstance().removeEventListener(network.BattleMsgEvent.GAME_READY, this.GameReadyEventCall, this);
            //叫地主结束
            network.BattleMsg.getInstance().removeEventListener(network.BattleMsgEvent.CALL_LANDLORD_OVER, this.CallLandLordOver, this);
            //下一个叫地主
            network.BattleMsg.getInstance().removeEventListener(network.BattleMsgEvent.CALL_LANDLORD_NEXT, this.CallLandLordNext, this);
            //收到出牌消息
            network.BattleMsg.getInstance().removeEventListener(network.BattleMsgEvent.PLAYER_CARDS, this.PlayCards, this);
            //游戏结束
            network.BattleMsg.getInstance().removeEventListener(network.BattleMsgEvent.GAME_OVER, this.GameOver, this);
            PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_LEVAE_ROOM_NOTIFY, this.leaveRoomNotify, this);
            if (this._playerTimer) {
                this._playerTimer.Release();
            }
            if (this._playerHeader_left) {
                this._playerHeader_left.Release();
            }
            if (this._playerHeader_right) {
                this._playerHeader_right.Release();
            }
        };
        BattleStageControl.Delay_ReadyKick = 30000; //15秒不准备踢出
        BattleStageControl.Delay_SendCardAni = 6000; //4秒发牌动画
        BattleStageControl.Delay_CallLand = 10000; //10秒叫地主
        BattleStageControl.Delay_ShowCard = 25000; //25秒游戏发牌
        return BattleStageControl;
    }(egret.EventDispatcher));
    battle.BattleStageControl = BattleStageControl;
    __reflect(BattleStageControl.prototype, "battle.BattleStageControl");
})(battle || (battle = {}));
var battle;
(function (battle) {
    /**
     * 卡牌控制类，控制卡牌显示位置，和出牌动画
     */
    var TableCardControl = (function () {
        function TableCardControl() {
            this._gameScene = null;
            this._landSprite = null; //地主牌
            this._tableSprite_1 = null;
            this._tableSprite_2 = null;
            this._tableSprite_3 = null;
        }
        TableCardControl.prototype.Init = function (gs) {
            this._gameScene = gs;
            this._landSprite = new egret.Sprite();
            this._tableSprite_1 = new egret.Sprite();
            this._tableSprite_2 = new egret.Sprite();
            this._tableSprite_3 = new egret.Sprite();
            this._gameScene.addChild(this._landSprite);
            this._gameScene.addChild(this._tableSprite_1);
            this._gameScene.addChild(this._tableSprite_2);
            this._gameScene.addChild(this._tableSprite_3);
            this._landSprite.x = 230;
            this._landSprite.y = 80;
            this._tableSprite_1.x = 20;
            this._tableSprite_1.y = 300;
            this._tableSprite_2.x = 340;
            this._tableSprite_2.y = 300;
            this._tableSprite_3.x = 20;
            this._tableSprite_3.y = 500;
        };
        TableCardControl.prototype.clearAll = function (cland) {
            if (cland === void 0) { cland = false; }
            this._tableSprite_1.removeChildren();
            this._tableSprite_2.removeChildren();
            this._tableSprite_3.removeChildren();
            if (cland) {
                this._landSprite.removeChildren();
            }
        };
        /**
         * 显示地主牌到 游戏中上位置
         */
        TableCardControl.prototype.ShowLandCard = function (clist) {
            this._landSprite.removeChildren();
            if (clist == null) {
                return;
            }
            var i = 0;
            var len = clist.length;
            for (i = 0; i < len; i++) {
                var card = MandPool.getInsByParm(battle.CardUI, clist[i]);
                this._landSprite.addChild(card);
                card.scaleX = card.scaleY = 0.4;
                card.x = (i % 7) * 64;
                card.y = 0;
            }
        };
        TableCardControl.prototype.ShowTableCard = function (localtabel, clist) {
            switch (localtabel) {
                case 1:
                    this.init_1(clist);
                    break;
                case 2:
                    this.init_2(clist);
                    break;
                case 3:
                    this.init_3(clist);
                    break;
                default:
                    break;
            }
        };
        // NOTE: 使用场景是什么 出牌动画
        TableCardControl.prototype.init_1 = function (clist) {
            this._tableSprite_1.removeChildren();
            if (clist == null) {
                return;
            }
            clist.reverse();
            clist.sort(function (a, b) {
                if (a % 100 > b % 100) {
                    return -1;
                }
                return 1;
            });
            var i = 0;
            var len = clist.length;
            for (i = 0; i < len; i++) {
                var card = MandPool.getInsByParm(battle.CardUI, clist[i]);
                this._tableSprite_1.addChild(card);
                card.scaleX = card.scaleY = TableCardControl.CardScale;
                card.x = (i % 7) * 35;
                card.y = Math.floor(i / 7) * 30;
            }
            this._tableSprite_1.x = 20;
            this._tableSprite_1.y = 100;
            this._tableSprite_1.alpha = 0;
            this._tableSprite_1.scaleX = this._tableSprite_1.scaleY = 1.5;
            this._tableSprite_1.alpha = 1;
            egret.Tween.get(this._tableSprite_1).to({ x: 20, y: 300, scaleX: 1, scaleY: 1, alpha: 1 }, 300, egret.Ease.circIn);
        };
        TableCardControl.prototype.init_2 = function (clist) {
            this._tableSprite_2.removeChildren();
            if (clist == null) {
                return;
            }
            clist.reverse();
            clist.sort(function (a, b) {
                if (a % 100 > b % 100) {
                    return -1;
                }
                return 1;
            });
            var i = 0;
            var len = clist.length;
            for (i = 0; i < len; i++) {
                var card = MandPool.getInsByParm(battle.CardUI, clist[i]);
                this._tableSprite_2.addChild(card);
                card.scaleX = card.scaleY = TableCardControl.CardScale;
                card.x = (i % 7) * 35;
                card.y = Math.floor(i / 7) * 30;
            }
            this._tableSprite_2.x = 500;
            this._tableSprite_2.y = 100;
            this._tableSprite_2.alpha = 0;
            this._tableSprite_2.scaleX = this._tableSprite_2.scaleY = 1.5;
            this._tableSprite_2.alpha = 1;
            egret.Tween.get(this._tableSprite_2).to({ x: 340, y: 300, scaleX: 1, scaleY: 1, alpha: 1 }, 300, egret.Ease.circIn);
        };
        TableCardControl.prototype.init_3 = function (clist) {
            this._tableSprite_3.removeChildren();
            if (clist == null) {
                return;
            }
            clist.reverse();
            clist.sort(function (a, b) {
                if (a % 100 > b % 100) {
                    return -1;
                }
                return 1;
            });
            var i = 0;
            var len = clist.length;
            var dis = 600;
            var gap1 = 50;
            var cnum = 10;
            if (len < cnum) {
                cnum = len;
            }
            var sx1 = (640 - (gap1 * cnum + battle.CardUI.CARDWIDTH * TableCardControl.CardScale)) / 2;
            for (i = 0; i < len; i++) {
                var card = MandPool.getInsByParm(battle.CardUI, clist[i]);
                this._tableSprite_3.addChild(card);
                card.scaleX = card.scaleY = TableCardControl.CardScale;
                card.x = sx1 + i % 10 * gap1;
                card.y = Math.floor(i / 10) * 30;
            }
            this._tableSprite_3.x = 20;
            this._tableSprite_3.y = 700;
            this._tableSprite_3.alpha = 0;
            this._tableSprite_3.scaleX = this._tableSprite_3.scaleY = 1.5;
            this._tableSprite_3.alpha = 1;
            egret.Tween.get(this._tableSprite_3).to({ x: 20, y: 450, scaleX: 1, scaleY: 1, alpha: 1 }, 300, egret.Ease.circIn);
        };
        TableCardControl.CardScale = 0.5;
        return TableCardControl;
    }());
    battle.TableCardControl = TableCardControl;
    __reflect(TableCardControl.prototype, "battle.TableCardControl");
})(battle || (battle = {}));
var battle;
(function (battle) {
    /**
     * 卡牌
     */
    var CardUI = (function (_super) {
        __extends(CardUI, _super);
        function CardUI(value) {
            var _this = _super.call(this) || this;
            _this._value = 0;
            _this._isselect = false;
            _this._isjump = false;
            _this._bg = null;
            _this._mask = null;
            _this._backbg = null;
            _this._typeimg1 = null;
            _this._typeimg2 = null;
            _this._numimg = null;
            _this._landimg = null;
            _this._value = value;
            if (value == 0) {
                _this.initBack();
            }
            else {
                _this.init();
            }
            return _this;
        }
        CardUI.prototype.addLand = function () {
            if (this._landimg == null) {
                this._landimg = new egret.Bitmap(RES.getRes("ui_flag_card"));
            }
            this.addChild(this._landimg);
        };
        CardUI.prototype.initBack = function () {
            this.touchEnabled = false;
            this.touchChildren = false;
            if (this._backbg == null) {
                this._backbg = new egret.Bitmap(RES.getRes("ui_cardback"));
            }
            this.addChild(this._backbg);
        };
        Object.defineProperty(CardUI.prototype, "Value", {
            get: function () {
                return this._value;
            },
            enumerable: true,
            configurable: true
        });
        CardUI.prototype.init = function () {
            this.touchEnabled = true;
            this.touchChildren = false;
            if (this._bg == null) {
                this._bg = new egret.Bitmap(RES.getRes("ui_card"));
            }
            if (this._mask == null) {
                this._mask = new egret.Bitmap(RES.getRes("ui_cardselect"));
            }
            this.addChild(this._bg);
            var type = Math.floor(this._value / 100);
            if (type < 5) {
                if (this._typeimg1 == null) {
                    this._typeimg1 = new egret.Bitmap(RES.getRes("ui_cardtype_" + type));
                }
                this.addChild(this._typeimg1);
                this._typeimg1.scaleX = this._typeimg1.scaleY = 1;
                this._typeimg1.x = 50;
                this._typeimg1.y = 75;
                if (this._typeimg2 == null) {
                    this._typeimg2 = new egret.Bitmap(RES.getRes("ui_cardtype_" + type));
                }
                this.addChild(this._typeimg2);
                this._typeimg2.scaleX = this._typeimg2.scaleY = 0.5;
                this._typeimg2.x = 11;
                this._typeimg2.y = 55;
            }
            else if (type == 9) {
                if (this._value == 999) {
                    if (this._typeimg1 == null) {
                        this._typeimg1 = new egret.Bitmap(RES.getRes("ui_cardnum9_99_dec"));
                    }
                    this.addChild(this._typeimg1);
                    this._typeimg1.x = 25;
                    this._typeimg1.y = 45;
                }
                else if (this._value == 998) {
                    if (this._typeimg1 == null) {
                        this._typeimg1 = new egret.Bitmap(RES.getRes("ui_cardnum9_98_dec"));
                    }
                    this.addChild(this._typeimg1);
                    this._typeimg1.x = 25;
                    this._typeimg1.y = 45;
                }
            }
            var color = 1;
            if (type == 2 || type == 4) {
                color = 2;
            }
            else if (type == 9) {
                color = 9;
            }
            var num = Math.floor(this._value % 100);
            if (this._numimg == null) {
                this._numimg = new egret.Bitmap(RES.getRes("ui_cardnum" + color + "_" + num));
            }
            this.addChild(this._numimg);
            this._numimg.x = 16;
            this._numimg.y = 9;
            this.addChild(this._mask);
            this._mask.visible = false;
        };
        Object.defineProperty(CardUI.prototype, "Select", {
            get: function () {
                return this._isselect;
            },
            set: function (isselect) {
                if (this._isselect == isselect) {
                    this._mask.visible = this._isselect;
                    if (this._isjump) {
                        this._mask.visible = true;
                    }
                    return;
                }
                this._isselect = isselect;
                this._mask.visible = this._isselect;
                if (this._isjump) {
                    this._mask.visible = true;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(CardUI.prototype, "Jump", {
            get: function () {
                return this._isjump;
            },
            set: function (isjump) {
                if (this._isjump == isjump) {
                    this._mask.visible = this._isjump;
                    return;
                }
                this._isjump = isjump;
                if (this._isjump) {
                    this.y -= 20;
                }
                else {
                    this.y += 20;
                }
                this._mask.visible = this._isjump;
                if (this._isjump) {
                    this._isselect = false;
                }
            },
            enumerable: true,
            configurable: true
        });
        CardUI.prototype.Release = function () {
            if (this._landimg && this._landimg.parent) {
                this._landimg.parent.removeChild(this._landimg);
            }
            this._isselect = false;
            this._isjump = false;
            this._mask.visible = false;
            this.scaleX = this.scaleY = 1;
            this.alpha = 1;
            if (this.parent) {
                this.parent.removeChild(this);
            }
            // MandPool.remand(this);
        };
        CardUI.CARDWIDTH = 135;
        CardUI.CARDHEIGHT = 179;
        return CardUI;
    }(egret.Sprite));
    battle.CardUI = CardUI;
    __reflect(CardUI.prototype, "battle.CardUI");
})(battle || (battle = {}));
var battle;
(function (battle) {
    var ChatMsgControl = (function () {
        function ChatMsgControl() {
            this._bg_1 = null;
            this._bg_2 = null;
            this._bg_3 = null;
            this._chat_1 = null;
            this._chat_2 = null;
            this._chat_3 = null;
            this._txt_1 = null;
            this._txt_2 = null;
            this._txt_3 = null;
            this._face_1 = null;
            this._face_2 = null;
            this._face_3 = null;
            this._gameScene = null;
        }
        ChatMsgControl.prototype.Init = function (gs) {
            this._gameScene = gs;
            this._gameScene.touchChildren = false;
            this._gameScene.touchEnabled = false;
            this._chat_1 = new egret.Sprite();
            this._chat_2 = new egret.Sprite();
            this._chat_3 = new egret.Sprite();
            this._bg_1 = new egret.Bitmap(RES.getRes("ui_chat_left"));
            this._bg_1.scale9Grid = new egret.Rectangle(95, 34, 200, 10);
            this._chat_1.addChild(this._bg_1);
            this._bg_2 = new egret.Bitmap(RES.getRes("ui_chat_right"));
            this._bg_2.scale9Grid = new egret.Rectangle(95, 34, 200, 10);
            this._chat_2.addChild(this._bg_2);
            this._bg_3 = new egret.Bitmap(RES.getRes("ui_chat_left"));
            this._bg_3.scale9Grid = new egret.Rectangle(95, 34, 200, 10);
            this._chat_3.addChild(this._bg_3);
            var txt = new egret.TextField();
            txt.textAlign = egret.HorizontalAlign.CENTER;
            txt.x = 28;
            txt.y = 18;
            txt.textColor = 0x804813;
            this._chat_1.addChild(txt);
            this._txt_1 = txt;
            var txt = new egret.TextField();
            txt.textAlign = egret.HorizontalAlign.CENTER;
            txt.x = 8;
            txt.y = 18;
            txt.textColor = 0x804813;
            this._chat_2.addChild(txt);
            this._txt_2 = txt;
            var txt = new egret.TextField();
            txt.textAlign = egret.HorizontalAlign.CENTER;
            txt.x = 28;
            txt.y = 18;
            txt.textColor = 0x804813;
            this._chat_3.addChild(txt);
            this._txt_3 = txt;
            this._face_1 = new egret.Sprite();
            this._face_2 = new egret.Sprite();
            this._face_3 = new egret.Sprite();
            this._gameScene.addChild(this._chat_1);
            this._gameScene.addChild(this._chat_2);
            this._gameScene.addChild(this._chat_3);
            this._gameScene.addChild(this._face_1);
            this._gameScene.addChild(this._face_2);
            this._gameScene.addChild(this._face_3);
            this._chat_1.x = 150;
            this._chat_1.y = 100;
            this._chat_2.x = 200;
            this._chat_2.y = 200;
            this._chat_3.x = 220;
            this._chat_3.y = 500;
            this._face_1.x = 150;
            this._face_1.y = 150;
            this._face_2.x = 320;
            this._face_2.y = 150;
            this._face_3.x = 220;
            this._face_3.y = 500;
            this._chat_1.visible = false;
            this._chat_2.visible = false;
            this._chat_3.visible = false;
            this._face_1.visible = false;
            this._face_2.visible = false;
            this._face_3.visible = false;
            this._chat_1.cacheAsBitmap = true;
            this._chat_2.cacheAsBitmap = true;
            this._chat_3.cacheAsBitmap = true;
            this._face_1.visible = false;
            this._face_2.visible = false;
            this._face_3.visible = false;
        };
        //public clearAll():void
        //{
        //    this._tableSprite_1.removeChildren();
        //    this._tableSprite_2.removeChildren();
        //    this._tableSprite_3.removeChildren();
        //}
        ChatMsgControl.prototype.ShowTableCard = function (localtabel, txt) {
            if (txt.indexOf("ani_chat_") >= 0) {
                if (this["initface_" + localtabel]) {
                    this["initface_" + localtabel](txt);
                }
            }
            else {
                if (this["init_" + localtabel]) {
                    this["init_" + localtabel](txt);
                }
            }
        };
        ChatMsgControl.prototype.init_1 = function (txt) {
            this._chat_1.visible = true;
            egret.Tween.removeTweens(this._chat_1);
            this._txt_1.text = txt;
            this._txt_1.width = 320;
            this._txt_1.width = this._txt_1.textWidth;
            if (this._txt_1.width > 280) {
                this._txt_1.width = 280;
            }
            else if (this._txt_1.width < 120) {
                this._txt_1.width = 120;
            }
            this._bg_1.width = this._txt_1.width + 80;
            this._bg_1.height = this._txt_1.height + 40;
            this._txt_1.x = this._bg_1.width - this._txt_1.width - 20;
            this._chat_1.x = 150;
            this._chat_1.y = 100;
            this._chat_1.alpha = 1;
            egret.Tween.get(this._chat_1).to({}, ChatMsgControl.flyTime).call(function () {
                this._chat_1.visible = false;
            }, this);
        };
        ChatMsgControl.prototype.init_2 = function (txt) {
            this._chat_2.visible = true;
            egret.Tween.removeTweens(this._chat_2);
            this._txt_2.text = txt;
            this._txt_2.width = 320;
            this._txt_2.width = this._txt_2.textWidth;
            if (this._txt_2.width > 280) {
                this._txt_2.width = 280;
            }
            else if (this._txt_2.width < 120) {
                this._txt_2.width = 120;
            }
            this._bg_2.width = this._txt_2.width + 80;
            this._bg_2.height = this._txt_2.height + 40;
            this._chat_2.x = 500 - this._bg_2.width;
            this._chat_2.y = 200;
            this._chat_2.alpha = 1;
            egret.Tween.get(this._chat_2).to({}, ChatMsgControl.flyTime).call(function () {
                this._chat_2.visible = false;
            }, this);
        };
        ChatMsgControl.prototype.init_3 = function (txt) {
            this._chat_3.visible = true;
            egret.Tween.removeTweens(this._chat_3);
            this._txt_3.text = txt;
            this._txt_3.width = 320;
            this._txt_3.width = this._txt_3.textWidth;
            if (this._txt_3.width > 280) {
                this._txt_3.width = 280;
            }
            else if (this._txt_3.width < 120) {
                this._txt_3.width = 120;
            }
            this._bg_3.width = this._txt_3.width + 80;
            this._bg_3.height = this._txt_3.height + 40;
            this._txt_3.x = this._bg_3.width - this._txt_3.width - 20;
            this._chat_3.x = Config.StageWidth / 2 - this._bg_3.width / 2;
            this._chat_3.y = 500;
            this._chat_3.alpha = 1;
            egret.Tween.get(this._chat_3).to({}, ChatMsgControl.flyTime).call(function () {
                this._chat_3.visible = false;
            }, this);
        };
        ChatMsgControl.prototype.initface_1 = function (txt) {
            this._face_1.visible = true;
            egret.Tween.removeTweens(this._face_1);
            this._face_1.removeChildren();
            this._face_1.x = 180;
            this._face_1.y = 150;
            this._face_1.alpha = 1;
            var mcDataFactory = new egret.MovieClipDataFactory(RES.getRes(txt + "_json"), RES.getRes(txt + "_png"));
            var mc1 = new egret.MovieClip(mcDataFactory.generateMovieClipData("chat"));
            mc1.name = "chat_facemc1";
            this._face_1.addChild(mc1);
            mc1.play(10);
            egret.Tween.get(this._face_1).to({}, ChatMsgControl.flyTime).call(function () {
                this._face_1.visible = false;
                this._face_1.removeChildren();
            }, this);
        };
        ChatMsgControl.prototype.initface_2 = function (txt) {
            this._face_2.visible = true;
            egret.Tween.removeTweens(this._face_2);
            this._face_2.removeChildren();
            this._face_2.x = 380;
            this._face_2.y = 150;
            this._face_2.alpha = 1;
            var mcDataFactory = new egret.MovieClipDataFactory(RES.getRes(txt + "_json"), RES.getRes(txt + "_png"));
            var mc1 = new egret.MovieClip(mcDataFactory.generateMovieClipData("chat"));
            mc1.name = "chat_facemc1";
            this._face_2.addChild(mc1);
            mc1.play(10);
            egret.Tween.get(this._face_2).to({}, ChatMsgControl.flyTime).call(function () {
                this._face_2.visible = false;
                this._face_2.removeChildren();
            }, this);
        };
        ChatMsgControl.prototype.initface_3 = function (txt) {
            this._face_3.visible = true;
            egret.Tween.removeTweens(this._face_3);
            this._face_3.removeChildren();
            this._face_3.x = 250;
            this._face_3.y = 500;
            this._face_3.alpha = 1;
            var mcDataFactory = new egret.MovieClipDataFactory(RES.getRes(txt + "_json"), RES.getRes(txt + "_png"));
            var mc1 = new egret.MovieClip(mcDataFactory.generateMovieClipData("chat"));
            mc1.name = "chat_facemc1";
            this._face_3.addChild(mc1);
            mc1.play(10);
            egret.Tween.get(this._face_3).to({}, ChatMsgControl.flyTime).call(function () {
                this._face_3.visible = false;
                this._face_3.removeChildren();
            }, this);
        };
        ChatMsgControl.flyTime = 3500;
        return ChatMsgControl;
    }());
    battle.ChatMsgControl = ChatMsgControl;
    __reflect(ChatMsgControl.prototype, "battle.ChatMsgControl");
})(battle || (battle = {}));
var battle;
(function (battle) {
    var CircleLoading = (function (_super) {
        __extends(CircleLoading, _super);
        function CircleLoading(bgurl) {
            var _this = _super.call(this) || this;
            _this._bg = null;
            _this._mask = null;
            _this.init(bgurl);
            return _this;
        }
        CircleLoading.prototype.init = function (bgurl) {
            this.touchEnabled = false;
            this.touchChildren = false;
            this._bg = new egret.Bitmap(RES.getRes(bgurl));
            this.addChild(this._bg);
            this._mask = new egret.Shape();
            this.addChild(this._mask);
            this.mask = this._mask;
            this.setProgress(0);
        };
        CircleLoading.prototype.setProgress = function (prog) {
            if (prog > 1 || prog <= 0) {
                return;
            }
            var bgwidth = this._bg.width;
            var bgheight = this._bg.height;
            var angle = Math.ceil(360 * prog);
            this.DrawSector(this._mask, bgwidth / 2, bgheight / 2, bgwidth / 2, angle, -90);
        };
        CircleLoading.prototype.DrawSector = function (mc, x, y, r, angle, startFrom) {
            if (x === void 0) { x = 200; }
            if (y === void 0) { y = 200; }
            if (r === void 0) { r = 100; }
            if (angle === void 0) { angle = -90; }
            if (startFrom === void 0) { startFrom = -90; }
            mc.graphics.clear();
            mc.graphics.beginFill(0x000000);
            mc.graphics.lineStyle(0, 0xff0000);
            mc.graphics.moveTo(x, y);
            angle = (Math.abs(angle) > 360) ? 360 : angle;
            var n = Math.ceil(Math.abs(angle) / 45);
            var angleA = angle / n;
            angleA = angleA * Math.PI / 180;
            startFrom = startFrom * Math.PI / 180;
            mc.graphics.lineTo(x + r * Math.cos(startFrom), y + r * Math.sin(startFrom));
            for (var i = 1; i <= n; i++) {
                startFrom += angleA;
                var angleMid = startFrom - angleA / 2;
                var bx = x + r / Math.cos(angleA / 2) * Math.cos(angleMid);
                var by = y + r / Math.cos(angleA / 2) * Math.sin(angleMid);
                var cx = x + r * Math.cos(startFrom);
                var cy = y + r * Math.sin(startFrom);
                mc.graphics.curveTo(bx, by, cx, cy);
            }
            if (angle != 360) {
                mc.graphics.lineTo(x, y);
            }
            mc.graphics.endFill(); // if you want a sector without filling color , please remove this line.
        };
        CircleLoading.prototype.Release = function () {
            if (this.parent) {
                this.parent.removeChild(this);
            }
        };
        return CircleLoading;
    }(egret.Sprite));
    battle.CircleLoading = CircleLoading;
    __reflect(CircleLoading.prototype, "battle.CircleLoading");
})(battle || (battle = {}));
var battle;
(function (battle) {
    var HouseRunning = (function (_super) {
        __extends(HouseRunning, _super);
        function HouseRunning() {
            var _this = _super.call(this) || this;
            _this._strList = null;
            _this._txt = null;
            _this._bgSprite = null;
            _this._scrollRect = null;
            return _this;
        }
        HouseRunning.prototype.Init = function () {
            this.touchChildren = false;
            this.touchEnabled = false;
            this.cacheAsBitmap = true;
            this._strList = new Array();
            this._bgSprite = new egret.Shape();
            this.addChild(this._bgSprite);
            this.drawBg();
            this._txt = new egret.TextField();
            this._txt.textColor = 0xffff00;
            this._txt.y = 10;
            this._txt.x = HouseRunning.BGWidth;
            this._txt.size = 30;
            this.addChild(this._txt);
            this._scrollRect = new egret.Rectangle(0, 0, HouseRunning.BGWidth, HouseRunning.BGHeight);
            this.scrollRect = this._scrollRect;
        };
        HouseRunning.prototype.Push = function (str) {
            if (this._strList.length > HouseRunning.MaxLen) {
                this._strList.shift();
            }
            this._strList.push(str);
            this.visible = true;
            if (this._strList.length == 1) {
                this._scrollRect.x = 0;
                this._txt.text = this._strList[0];
                this._scrollRect.width = (HouseRunning.BGWidth + this._txt.textWidth);
                this.drawBg();
            }
            this.scrollRect = this._scrollRect;
        };
        HouseRunning.prototype.drawBg = function () {
            if (this._scrollRect == null) {
                return;
            }
            this._bgSprite.graphics.clear();
            this._bgSprite.graphics.beginFill(HouseRunning.BGCOLOR, 0.4);
            this._bgSprite.graphics.drawRect(0, 0, this._scrollRect.width + HouseRunning.BGWidth, HouseRunning.BGHeight);
            this._bgSprite.graphics.endFill();
        };
        HouseRunning.prototype.Update = function () {
            if (this._strList.length < 1) {
                return;
            }
            this._scrollRect.x += 1;
            if (this.scrollRect.x > (HouseRunning.BGWidth + this._txt.textWidth)) {
                this._strList.shift();
                if (this._strList.length < 1) {
                    this.visible = false;
                    return;
                }
                this._scrollRect.x = 0;
                this._txt.text = this._strList[0];
                this._scrollRect.width = (HouseRunning.BGWidth + this._txt.textWidth);
                this.drawBg();
            }
            this.scrollRect = this._scrollRect;
        };
        HouseRunning.BGCOLOR = 0x000000;
        HouseRunning.BGHeight = 45;
        HouseRunning.BGWidth = 400;
        HouseRunning.MaxLen = 3;
        return HouseRunning;
    }(egret.Sprite));
    battle.HouseRunning = HouseRunning;
    __reflect(HouseRunning.prototype, "battle.HouseRunning");
})(battle || (battle = {}));
var MandPool = (function () {
    function MandPool() {
    }
    MandPool.getInsByParm = function (cT, parm1) {
        if (cT != null) {
            var strT = egret.getQualifiedClassName(cT);
            var arr = this.s_dict[strT];
            if (null == arr) {
                arr = [];
                this.s_dict[strT] = arr;
            }
            if (arr.length > 0) {
                var i = 0;
                var len = arr.length;
                for (i = len - 1; i >= 0; i--) {
                    var temp = arr[i];
                    if (temp && temp["paramflag"] == parm1) {
                        arr.splice(i, 1);
                        return temp;
                    }
                }
            }
            var rtemp = new cT(parm1);
            rtemp["paramflag"] = parm1;
            return rtemp;
        }
        return null;
    };
    /**
     * 获取一个实例，可能是新创建的，也可能是旧的
     */
    MandPool.getIns = function (cT, parm1) {
        if (parm1 === void 0) { parm1 = null; }
        if (cT != null) {
            var strT = egret.getQualifiedClassName(cT);
            var arr = this.s_dict[strT];
            if (null == arr) {
                arr = [];
                this.s_dict[strT] = arr;
            }
            if (arr.length > 0) {
                var obIns = arr.pop();
                if (obIns["onCheckout"]) {
                    obIns.onCheckout();
                }
                return obIns;
            }
            else {
                var rtemp = new cT(parm1);
                rtemp["paramflag"] = parm1;
                return rtemp;
            }
        }
        return null;
    };
    /**
     * 退还Object
     */
    MandPool.remand = function (obj) {
        if (obj != null) {
            var strT = egret.getQualifiedClassName(obj);
            var arr = this.s_dict[strT];
            if (arr != null) {
                arr.push(obj);
                if (obj["onRemand"]) {
                    console.log("MandPool.remand(this);");
                    obj.onRemand();
                }
            }
            /*以上为对象不为空的处理
            */
        }
    };
    /**
     *
     */
    MandPool.getCount = function (cT) {
        var arr = this.s_dict[cT];
        if (arr != null)
            return arr.length;
        return 0;
    };
    /**
     *
     */
    MandPool.s_dict = {};
    return MandPool;
}());
__reflect(MandPool.prototype, "MandPool");
var battle;
(function (battle) {
    var MyCardControl = (function () {
        function MyCardControl() {
            this._btnProxy = null;
            this._tableList = []; //桌面牌,用于提示
            this._type = null;
            this._prompt = null;
            this._prompt2 = null;
            this._compare = null;
            this._lastCard = null; //防止move多次选择
            this._startCard = null;
            this._cardLayer = null; //存放卡牌显示的容器
            this._gameScene = null;
            this._player = null;
            this._cardVlist = null; //点选牌的列表
            this._ismousedown = false;
            this._island = false;
            this._canshowAll = false;
        }
        MyCardControl.prototype.Init = function (gs) {
            this._gameScene = gs;
        };
        //设置地主标
        MyCardControl.prototype.SetPlayerLandFlag = function (landid) {
            this._island = landid == 3;
            //this.setCard();
        };
        Object.defineProperty(MyCardControl.prototype, "CanShowAll", {
            //是否能够全下
            set: function (c) {
                this._canshowAll = c;
            },
            enumerable: true,
            configurable: true
        });
        MyCardControl.prototype.SetMainPlayer = function (player) {
            this._gameScene.removeChildren();
            this._type = new gameLogic.PlayCardTypes();
            this._prompt = new gameLogic.Prompt();
            this._prompt2 = new gameLogic.Prompt2();
            this._compare = new gameLogic.Compare();
            this._player = player;
            this._cardVlist = [];
            this._cardLayer = new egret.Sprite();
            this._gameScene.addChild(this._cardLayer);
            this._cardLayer.x = 0;
            this._cardLayer.y = Config.StageHeight - MyCardControl.DOWNGAP - battle.CardUI.CARDHEIGHT * 2 - MyCardControl.VERCARGAP;
            this._cardLayer.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchBegin, this);
            this._cardLayer.addEventListener(egret.TouchEvent.TOUCH_END, this.onTouchEnd, this);
            this._cardLayer.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.onTouchEnd, this);
            this._cardLayer.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.onTouchMove, this);
            //this._cardLayer.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onTouchTap,this);
            this.setCard();
        };
        MyCardControl.prototype.SetButtonCtl = function (btnproxy) {
            this._btnProxy = btnproxy;
        };
        MyCardControl.prototype.getHasBigger = function () {
            if (this._tableList == null || this._tableList.length < 1) {
                return true;
            }
            var rlen = this._cardVlist.length;
            var ri = 0;
            var rj = 0;
            var mylist = [];
            for (ri = 0; ri < rlen; ri++) {
                var card = this._cardVlist[ri];
                mylist.push(card.Value);
            }
            var cld1 = this._type.GetType(mylist);
            var cld2 = this._type.GetType(this._tableList);
            var cld3 = null;
            if (cld2.Type == gameLogic.PlayCardTypes.Types_Error) {
                return true; //cld3= this._prompt.GetPrompt(cld1, null, 0, 0, false);            //todo:这里传入其他两个玩家的数量
            }
            else {
                cld3 = this._prompt.GetPrompt(cld1, cld2, 0, 0, false, false); //todo:这里传入其他两个玩家的数量
                if (cld3 == null) {
                    cld3 = this._prompt2.GetPrompt(cld1, cld2);
                }
            }
            if (cld3 == null) {
                return false;
            }
            return true;
        };
        MyCardControl.prototype.CanAllShow = function () {
            var chooselist = this.GetWillShowList();
            if (chooselist != null && chooselist.length > 0) {
                return true;
            }
            var rlen = this._cardVlist.length;
            var ri = 0;
            var rj = 0;
            var mylist = [];
            for (ri = 0; ri < rlen; ri++) {
                var card = this._cardVlist[ri];
                card.Select = false;
                card.Jump = false;
                mylist.push(card.Value);
            }
            var cld1 = this._type.GetType(mylist);
            if (cld1.Type != gameLogic.PlayCardTypes.Types_Error) {
                for (ri = 0; ri < rlen; ri++) {
                    var card = this._cardVlist[ri];
                    card.Select = false;
                    card.Jump = true;
                    mylist.push(card.Value);
                }
                return true;
            }
            return true;
        };
        //重置
        MyCardControl.prototype.Reset = function () {
            var rlen = this._cardVlist.length;
            var ri = 0;
            for (ri = 0; ri < rlen; ri++) {
                var card = this._cardVlist[ri];
                card.Select = false;
                card.Jump = false;
            }
        };
        //能大过返回true,ismust:强制提示,不管有没有弹起牌
        MyCardControl.prototype.Prompt = function (isnew, ismust) {
            if (isnew) {
                return this.CanAllShow();
            }
            if (!ismust) {
                var chooselist = this.GetWillShowList();
                if (chooselist != null && chooselist.length > 0) {
                    return true;
                }
            }
            var rlen = this._cardVlist.length;
            var ri = 0;
            var rj = 0;
            var mylist = [];
            for (ri = 0; ri < rlen; ri++) {
                var card = this._cardVlist[ri];
                card.Select = false;
                card.Jump = false;
                mylist.push(card.Value);
            }
            var cld1 = this._type.GetType(mylist);
            var cld2 = this._type.GetType(this._tableList);
            var cld3 = null;
            if (cld2.Type == gameLogic.PlayCardTypes.Types_Error) {
                cld3 = this._prompt.GetPrompt(cld1, null, 0, 0, false, false); //todo:这里传入其他两个玩家的数量
            }
            else {
                cld3 = this._prompt.GetPrompt(cld1, cld2, 0, 0, false, false); //todo:这里传入其他两个玩家的数量
                if (cld3 == null) {
                    cld3 = this._prompt2.GetPrompt(cld1, cld2);
                }
            }
            if (cld3 == null) {
                return false;
            }
            var list = cld3.List;
            var jlen = list.length;
            for (ri = 0; ri < rlen; ri++) {
                var card = this._cardVlist[ri];
                for (rj = 0; rj < jlen; rj++) {
                    if (list[rj] == card.Value) {
                        card.Jump = true;
                        break;
                    }
                }
            }
            return true;
        };
        MyCardControl.prototype.SetTableList = function (clist) {
            this._tableList = clist;
        };
        //发送完成,返回消息
        MyCardControl.prototype.SendOver = function (list) {
            this.setCard(list);
        };
        //获取点选的牌
        MyCardControl.prototype.GetWillShowList = function (notype) {
            if (notype === void 0) { notype = false; }
            var i = 0;
            var len = this._cardVlist.length;
            var card;
            var list = [];
            for (i = len - 1; i >= 0; i--) {
                card = this._cardVlist[i];
                if (card.Jump) {
                    //this._cardVlist.splice(i,1);
                    list.push(card.Value);
                    //this._player.removeCards([card.Value]);
                    //card.Release();
                }
            }
            //判定牌是否是有效
            var cls = this._type.GetType(list);
            if (cls.Type == gameLogic.PlayCardTypes.Types_Error) {
                if (this._canshowAll && cls.List.length > 1 && cls.SingleArr.length < 1 && cls.HasBomb() == false) {
                    return list;
                }
                if (notype == false) {
                    return null;
                }
                else {
                    if (list.length > 0) {
                        return list;
                    }
                    else {
                        return null;
                    }
                }
            }
            //this.RemoveJump();
            return list;
        };
        Object.defineProperty(MyCardControl.prototype, "Visible", {
            set: function (v) {
                if (this._cardLayer) {
                    this._cardLayer.visible = v;
                }
            },
            enumerable: true,
            configurable: true
        });
        MyCardControl.prototype.onTouchBegin = function (e) {
            var rlen = this._cardVlist.length;
            var ri = 0;
            for (ri = 0; ri < rlen; ri++) {
                var card = this._cardVlist[ri];
                if (card == e.target) {
                    card.Select = true;
                    this._startCard = card;
                    this._lastCard = card;
                }
                else {
                    card.Select = false;
                }
            }
            this._ismousedown = true;
        };
        MyCardControl.prototype.onTouchMove = function (e) {
            var target = e.target;
            if (!(target instanceof battle.CardUI) || this._lastCard == null) {
                return;
            }
            if (target == this._lastCard) {
                return;
            }
            this._lastCard = target;
            var vlen = this._cardVlist.length;
            var i = 0;
            var card;
            var flag = 0;
            for (i = 0; i < vlen; i++) {
                card = this._cardVlist[i];
                if (flag == 1) {
                    card.Select = true;
                }
                else {
                    card.Select = false;
                }
                if (card == target) {
                    flag++;
                    card.Select = true;
                }
                if (card == this._startCard) {
                    flag++;
                    card.Select = true;
                }
            }
            return;
        };
        /**
         * 点选牌完成后进行牌类型比较
         */
        MyCardControl.prototype.onTouchEnd = function (e) {
            if (this._ismousedown == false) {
                return;
            }
            this._ismousedown = false;
            var rlen = this._cardVlist.length;
            var i = 0;
            var seltarr = [];
            var promparr = [];
            var mylist = [];
            var card;
            var alljump = true;
            var hasjump = false;
            var hasjumpall = false;
            for (i = 0; i < rlen; i++) {
                card = this._cardVlist[i];
                mylist.push(card.Value);
                if (card == e.target) {
                    card.Select = true;
                    //break;
                }
                if (card.Select == true) {
                    promparr.push(card.Value);
                    seltarr.push(card);
                    if (card.Jump == false) {
                        alljump = false;
                    }
                    else {
                        hasjump = true;
                    }
                }
                if (card.Jump == true) {
                    hasjumpall = true;
                }
            }
            //选择的都是已经弹出的..全部不弹出
            if (alljump) {
                rlen = seltarr.length;
                for (i = 0; i < rlen; i++) {
                    card = seltarr[i];
                    card.Jump = false;
                    card.Select = false;
                }
                this.SetBtnVisible();
                return;
            }
            var mycld = this._type.GetType(mylist);
            var cld = this._type.GetType(promparr);
            if (cld.Type == gameLogic.PlayCardTypes.Types_Error && hasjumpall == false) {
                var cld2 = null;
                if (cld.List.length >= 5) {
                    cld2 = this._prompt.GetPrompt(cld, null, 0, 0, false, false); //todo:这里传入其他两个玩家的数量
                    //提示牌大于3张而且大于选择牌的2/3的牌才优化提示
                    if (cld2 && (cld2.Type == gameLogic.PlayCardTypes.Types_List || (cld2.List.length > 3))) {
                        cld = cld2;
                    }
                }
                else {
                    cld2 = this._prompt.GetPromptContain(mycld, cld);
                    if (cld2 && cld2.Type == gameLogic.PlayCardTypes.Types_List) {
                        cld = cld2;
                    }
                }
            }
            //if(cld.List.length==1&&hasjumpall == false) //单击一张全部弹起
            //{
            //    var cnuu:number=mycld.getCountOfNum(cld.List[0]);
            //    if(cnuu>1)
            //    {
            //
            //        var cnulst:Array<number>=mycld.getValueByNum(cld.List[0],cnuu);
            //        var list1=cld.List;
            //        var flist=list1.concat(cnulst);
            //        cld=this._type.GetType(flist);
            //    }
            //}
            var len2 = cld.List.length;
            var j = 0;
            var value = 0;
            for (i = 0; i < rlen; i++) {
                card = this._cardVlist[i];
                card.Select = false;
                for (j = 0; j < len2; j++) {
                    value = cld.List[j];
                    if (value == card.Value) {
                        card.Jump = true;
                    }
                }
            }
            this.SetBtnVisible();
        };
        /**
         * 点选牌后，进行牌类型大小比较
         */
        MyCardControl.prototype.SetBtnVisible = function () {
            if (this._btnProxy.State != battle.BattleBtnControl.STATE_Playing) {
                return;
            }
            var jlist = this.GetWillShowList();
            var tcld = null;
            var scld = null;
            if (jlist == null) {
                this._btnProxy.PlayingShow(false);
            }
            else {
                if (this._tableList == null || this._tableList.length < 1) {
                    this._btnProxy.PlayingShow(true);
                    return;
                }
                tcld = this._type.GetType(this._tableList); //获取牌桌上的牌类型
                scld = this._type.GetType(jlist); //获取当前玩家要出牌的类型
                if (this._compare.IsBiger(scld, tcld)) {
                    this._btnProxy.PlayingShow(true);
                }
                else {
                    this._btnProxy.PlayingShow(false);
                }
            }
        };
        MyCardControl.prototype.setCard = function (lt) {
            var rlen = this._cardVlist.length;
            var ri = 0;
            for (ri = 0; ri < rlen; ri++) {
                var card = this._cardVlist[ri];
                card.Release();
            }
            this._cardVlist = [];
            if (lt) {
                this._player.removeCards(lt);
            }
            var clist = this._player.cardList;
            console.info("MyCardControl  setCard length:", this._player.cardNumber);
            clist.sort(function (a, b) {
                if (a % 100 == b % 100) {
                    if (a > b) {
                        return 1;
                    }
                    else {
                        return -1;
                    }
                }
                else if (a % 100 > b % 100) {
                    return -1;
                }
                return 1;
            });
            var list = this.dividArr();
            var list1 = list[0];
            var list2 = list[1];
            var len1 = list1.length;
            var len2 = list2.length;
            var dis = Config.StageWidth - MyCardControl.LEFTGAP - MyCardControl.RIGHTGAP - battle.CardUI.CARDWIDTH;
            var cy1 = 0; //Config.StageHeight-MyCardControl.DOWNGAP-CardUI.CARDHEIGHT;
            var cy2 = cy1 + MyCardControl.VERCARGAP + battle.CardUI.CARDHEIGHT;
            var gap1 = dis / (len1 - 1);
            var gap2 = dis / (len2 - 1);
            var i = 0;
            if (gap1 > MyCardControl.HORCARGAP) {
                gap1 = MyCardControl.HORCARGAP;
            }
            if (gap2 > MyCardControl.HORCARGAP) {
                gap2 = MyCardControl.HORCARGAP;
            }
            var sx1 = (Config.StageWidth - (gap1 * (len1 - 1) + battle.CardUI.CARDWIDTH)) / 2;
            var sx2 = (Config.StageWidth - (gap2 * (len2 - 1) + battle.CardUI.CARDWIDTH)) / 2;
            var lastCard = null;
            for (i = 0; i < len1; i++) {
                var card = MandPool.getInsByParm(battle.CardUI, list1[i]);
                card.y = cy1;
                card.x = sx1 + i * gap1;
                this._cardLayer.addChild(card);
                this._cardVlist.push(card);
                lastCard = card;
            }
            for (i = 0; i < len2; i++) {
                var card = MandPool.getInsByParm(battle.CardUI, list2[i]);
                card.y = cy2;
                card.x = sx2 + i * gap2;
                this._cardLayer.addChild(card);
                this._cardVlist.push(card);
                lastCard = card;
            }
            if (this._island) {
                lastCard.addLand();
            }
        };
        //划分为上下显示的两个数组
        MyCardControl.prototype.dividArr = function () {
            var arr1 = [];
            var arr2 = [];
            var len = this._player.cardNumber;
            var i = 0;
            var cardvalue;
            //先分配到两个数组
            for (i = 0; i < 10; i++) {
                cardvalue = this._player.cardList[i];
                if (cardvalue) {
                    arr1.push(cardvalue);
                }
            }
            for (i = 10; i < 20; i++) {
                cardvalue = this._player.cardList[i];
                if (cardvalue) {
                    arr2.push(cardvalue);
                }
            }
            //检查第二个数组的第一个数字第一个数组中是否存在(同样数字应该在一列)
            var samevalue;
            if ((arr2[0])) {
                samevalue = (arr2[0]) % 100;
            }
            var len1 = arr1.length;
            var len2 = arr2.length;
            var long = 0;
            if (samevalue) {
                for (i = len1 - 1; i >= 0; i--) {
                    if (samevalue == (arr1[i]) % 100) {
                        long++;
                        if (long + len2 < 10) {
                            arr2.unshift(arr1.pop());
                        }
                    }
                    else {
                        break;
                    }
                }
            }
            return [arr1, arr2];
        };
        MyCardControl.prototype.Release = function () {
            this._gameScene.removeChildren();
        };
        MyCardControl.LEFTGAP = 17; //距离左侧距离
        MyCardControl.RIGHTGAP = 17; //距离右侧距离
        MyCardControl.DOWNGAP = 98; //距离下方距离
        MyCardControl.VERCARGAP = 35; //纵向卡牌间隔
        MyCardControl.HORCARGAP = 100; //横向卡牌间隔(最大)
        return MyCardControl;
    }());
    battle.MyCardControl = MyCardControl;
    __reflect(MyCardControl.prototype, "battle.MyCardControl");
})(battle || (battle = {}));
var battle;
(function (battle) {
    var Player = (function (_super) {
        __extends(Player, _super);
        function Player() {
            var _this = _super.call(this) || this;
            _this.cardList = []; //牌列表
            _this.isLandLord = false; //是否是地主
            _this.seatNo = 0; //座位号
            _this.LocalTableId = 0; //上下家标识 1 上家， 2下家 3-为自己
            _this.IsReady = false;
            _this.landlordScore = 0; //叫地主分
            _this._cardNumber = 0; //牌数量
            return _this;
        }
        Player.prototype.AddcardList = function (cards) {
            if (cards == null) {
                return;
            }
            for (var i in cards) {
                this.cardList.push(cards[i]);
            }
        };
        Object.defineProperty(Player.prototype, "cardNumber", {
            /**
             * 获取牌数量
             */
            get: function () {
                return this.cardList.length;
            },
            enumerable: true,
            configurable: true
        });
        /**
         * 叫地主
         */
        Player.prototype.callLandlord = function (value) {
        };
        /**
         * 移除牌
         */
        Player.prototype.removeCards = function (arr) {
            if (arr == null) {
                return;
            }
            var i = 0;
            var j = 0;
            var len = arr.length;
            for (i = 0; i < len; i++) {
                for (j = this.cardList.length - 1; j >= 0; j--) {
                    if (this.cardList[j] == arr[i]) {
                        this.cardList.splice(j, 1);
                        break;
                    }
                }
            }
        };
        /**
         * 出牌
         */
        Player.prototype.playCards = function (arr) {
            if (arr == null) {
                return;
            }
            var i = 0;
            var j = 0;
            var len = arr.length;
            for (i = 0; i < len; i++) {
                for (j = this.cardList.length - 1; j >= 0; j--) {
                    if (this.cardList[j] == arr[i]) {
                        this.cardList.splice(j, 1);
                        break;
                    }
                }
            }
        };
        Player.prototype.clearPlayer = function () {
            this.cardList = [];
            this.landlordScore = 0;
            this.seatNo = 0;
            this.isLandLord = false;
            this.LocalTableId = 0;
            this._cardNumber = 0;
        };
        return Player;
    }(GUser));
    battle.Player = Player;
    __reflect(Player.prototype, "battle.Player");
})(battle || (battle = {}));
/**
 * 显示对手头像
 */
var battle;
(function (battle) {
    var PlayerHead = (function (_super) {
        __extends(PlayerHead, _super);
        function PlayerHead() {
            var _this = _super.call(this) || this;
            _this._playerData = null;
            _this._pInfo = null;
            _this._headsp = null;
            _this._avatarsp = null;
            _this._backCardSp = null; //对手玩家的背面牌
            _this._isReady = false;
            _this._isAuto = false;
            _this._isOwner = false;
            _this._loc = 0; //位置 ,1左上,2右上,3下
            _this._ready_hand = null;
            _this._landflag = null;
            _this._cardNumTxt = null;
            _this._init = false;
            return _this;
        }
        PlayerHead.prototype.Init = function (pd) {
            if (this._init) {
                console.log("请先执行release");
                return;
            }
            this.touchEnabled = false;
            this._loc = pd.LocalTableId;
            this._playerData = pd;
            this.setReady();
            this.setHead();
            this.setBackCard();
            this.setTapInfo();
            this.Ready = true;
            this.ShowCard = false;
            this._headsp.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchBegin, this);
            this._headsp.addEventListener(egret.TouchEvent.TOUCH_END, this.onTouchEnd, this);
            this._headsp.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.onTouchEnd, this);
            this._init = true;
        };
        PlayerHead.prototype.setHead = function () {
            this._headsp = new battle.PlayerHeadFrame();
            this._headsp.Init(this._playerData.avator);
            this.addChild(this._headsp);
            this._headsp.touchEnabled = true;
        };
        PlayerHead.prototype.setTapInfo = function () {
            this._pInfo = new battle.PlayerInfo();
            this._pInfo.Init(this._playerData);
            this.addChild(this._pInfo);
            if (this._loc == 1) {
                this._pInfo.x = 100;
                this._pInfo.y = 0;
            }
            else if (this._loc == 2) {
                this._pInfo.x = -202;
                this._pInfo.y = 0;
            }
            else if (this._loc == 3) {
                this._pInfo.x = 100;
                this._pInfo.y = -125;
            }
            this._pInfo.touchChildren = false;
            this._pInfo.touchEnabled = false;
            this._pInfo.visible = false;
        };
        PlayerHead.prototype.setReady = function () {
            this._ready_hand = new egret.Bitmap(RES.getRes("ui_ready_hand"));
            this.addChild(this._ready_hand);
            this._ready_hand.x = -45;
            this._ready_hand.y = 0;
            this._ready_hand.visible = false;
        };
        PlayerHead.prototype.setBackCard = function () {
            if (this._loc == 3) {
                return;
            }
            this._backCardSp = new egret.Sprite();
            this.addChild(this._backCardSp);
            var i = 0;
            for (i = 0; i < 1; i++) {
                var card = MandPool.getInsByParm(battle.CardUI, 0);
                this._backCardSp.addChild(card);
                card.x = 0 + i * 10;
                card.y = 0;
            }
            this._backCardSp.scaleX = this._backCardSp.scaleY = 0.5;
            this._cardNumTxt = new egret.TextField();
            this._cardNumTxt.width = 200; //120;
            this._cardNumTxt.size = 100; //90
            this._cardNumTxt.textColor = 0xffff33; //0x00ffff;//0x3abdff;
            this._cardNumTxt.stroke = 5;
            this._cardNumTxt.strokeColor = 0x990000;
            this._cardNumTxt.textAlign = egret.HorizontalAlign.CENTER;
            this._backCardSp.addChild(this._cardNumTxt);
            this._cardNumTxt.text = "17";
            this._cardNumTxt.x = -35;
            this._cardNumTxt.y = 50;
            if (this._loc == 1) {
                this._backCardSp.x = 100; //45;
            }
            else if (this._loc == 2) {
                this._backCardSp.x = -70;
            }
            this._backCardSp.y = 10;
            this._backCardSp.cacheAsBitmap = true;
        };
        Object.defineProperty(PlayerHead.prototype, "ShowCard", {
            set: function (isshow) {
                if (this._backCardSp) {
                    this._backCardSp.visible = isshow;
                    if (isshow == false) {
                        this._cardNumTxt.text = "";
                    }
                }
            },
            enumerable: true,
            configurable: true
        });
        PlayerHead.prototype.UpdateCardNum = function () {
            console.info("UpdateCardNum " + this._playerData.cardNumber);
            if (this._cardNumTxt) {
                this._cardNumTxt.text = "" + this._playerData.cardNumber;
            }
        };
        PlayerHead.prototype.onTouchBegin = function (e) {
            this._pInfo.visible = true;
            this._pInfo.ReSet();
        };
        PlayerHead.prototype.onTouchEnd = function (e) {
            this._pInfo.visible = false;
        };
        Object.defineProperty(PlayerHead.prototype, "Ready", {
            set: function (ready) {
                if (this._isReady == ready) {
                    return;
                }
                this._isReady = ready;
                this._ready_hand.visible = this._isReady;
                if (this._loc == 1) {
                    this._ready_hand.x = 100;
                }
                else if (this._loc == 2) {
                    this._ready_hand.x = -45;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PlayerHead.prototype, "IsLandOwner", {
            set: function (isowner) {
                this._isOwner = isowner;
                if (this._landflag && this._landflag.parent) {
                    this._landflag.parent.removeChild(this._landflag);
                }
                if (this._isOwner) {
                    this._landflag = new egret.Bitmap(RES.getRes("ui_flag_landowner"));
                }
                else {
                    this._landflag = new egret.Bitmap(RES.getRes("ui_flag_farmer"));
                }
                this.addChild(this._landflag);
                if (this._headsp) {
                    this._headsp.visible = false;
                }
                this._landflag.x = 0;
                this._landflag.y = -90;
            },
            enumerable: true,
            configurable: true
        });
        //是否显示地主图片,是否地主
        PlayerHead.prototype.LandFlagVisible = function (isshow, island) {
            if (this._landflag) {
                this._landflag.visible = isshow;
            }
            if (this._headsp) {
                this._headsp.visible = !isshow;
            }
            if (isshow) {
                this.IsLandOwner = island;
            }
        };
        PlayerHead.prototype.Release = function () {
            if (this._headsp) {
                this._headsp.removeChildren();
                this._headsp.removeEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onTouchBegin, this);
                this._headsp.removeEventListener(egret.TouchEvent.TOUCH_END, this.onTouchEnd, this);
                this._headsp.removeEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.onTouchEnd, this);
            }
            if (this._landflag) {
                egret.Tween.removeTweens(this._landflag);
            }
            this._playerData = null;
            this._pInfo = null;
            this._headsp = null;
            this._avatarsp = null;
            this._backCardSp = null; //对手玩家的背面牌
            this._isReady = false;
            this._isOwner = false;
            this._isAuto = false;
            this._loc = 0; //位置 ,1左上,2右上,3下
            this._ready_hand = null;
            this._landflag = null;
            this._cardNumTxt = null;
            this.removeChildren();
            if (this.parent) {
                this.parent.removeChild(this);
            }
            this._init = false;
        };
        return PlayerHead;
    }(egret.Sprite));
    battle.PlayerHead = PlayerHead;
    __reflect(PlayerHead.prototype, "battle.PlayerHead");
})(battle || (battle = {}));
/**
 * Created by Administrator on 2015/12/25.
 */
var battle;
(function (battle) {
    var PlayerHeadFrame = (function (_super) {
        __extends(PlayerHeadFrame, _super);
        function PlayerHeadFrame() {
            var _this = _super.call(this) || this;
            _this._headsp = null;
            return _this;
        }
        PlayerHeadFrame.prototype.Init = function (avatar) {
            var bg = new egret.Bitmap(RES.getRes("ui_head_bg"));
            this._headsp = new egret.Sprite();
            this.addChild(this._headsp);
            this._headsp.addChild(bg);
            var headImg = new eui.Image();
            headImg.width = 88;
            headImg.height = 88;
            headImg.x = 6;
            headImg.y = 6;
            headImg.source = avatar;
            this._headsp.addChild(headImg);
            //RES.getResByUrl(avatar, this.getImgOver, this,RES.ResourceItem.TYPE_IMAGE);
            this.touchChildren = false;
        };
        // private getImgOver(event:egret.Texture):void {
        //     console.log("getImgOver",event);
        //     var bit:egret.Bitmap = new egret.Bitmap(event);
        //     bit.width = 88;
        //     bit.height = 88;
        //     bit.x=6;
        //     bit.y=6;
        //     if(this._headsp)
        //     {
        //         this._headsp.addChild(bit);
        //     }
        // }
        PlayerHeadFrame.prototype.Release = function () {
            if (this._headsp) {
                this._headsp.removeChildren();
            }
            this.removeChildren();
            if (this.parent) {
                this.parent.removeChild(this);
            }
        };
        return PlayerHeadFrame;
    }(egret.Sprite));
    battle.PlayerHeadFrame = PlayerHeadFrame;
    __reflect(PlayerHeadFrame.prototype, "battle.PlayerHeadFrame");
})(battle || (battle = {}));
/**
 * 点击玩家头像显示玩家头像信息
 */
var battle;
(function (battle) {
    var PlayerInfo = (function (_super) {
        __extends(PlayerInfo, _super);
        function PlayerInfo() {
            var _this = _super.call(this) || this;
            _this._scoretxt = null;
            _this._cointxt = null;
            _this._player = null;
            _this._jifen = "积分: ";
            return _this;
        }
        PlayerInfo.prototype.ReSet = function () {
            this._scoretxt.text = this._jifen + this._player.pointValue;
        };
        PlayerInfo.prototype.Init = function (pld) {
            var bg = new egret.Bitmap(RES.getRes("ui_info_bg"));
            bg.scale9Grid = new egret.Rectangle(35, 75, 130, 60);
            this.addChild(bg);
            this._player = pld;
            var nametxt = new egret.TextField();
            nametxt.textColor = 0x804813;
            nametxt.textAlign = egret.HorizontalAlign.LEFT;
            nametxt.size = 24;
            this.addChild(nametxt);
            nametxt.x = 5;
            nametxt.y = 20;
            nametxt.width = 190;
            nametxt.text = pld.nickName;
            var scoretxt = new egret.TextField();
            scoretxt.textColor = 0x804813;
            scoretxt.textAlign = egret.HorizontalAlign.LEFT;
            scoretxt.size = 24;
            scoretxt.x = 25;
            scoretxt.y = 70;
            scoretxt.width = 170;
            scoretxt.text = this._jifen + pld.pointValue;
            this._scoretxt = scoretxt;
            var cointxt = new egret.TextField();
            cointxt.textColor = 0x804813;
            cointxt.textAlign = egret.HorizontalAlign.LEFT;
            cointxt.size = 24;
            cointxt.x = 25;
            cointxt.y = 100;
            cointxt.width = 170;
            this._cointxt = cointxt;
            this.addChild(scoretxt);
        };
        return PlayerInfo;
    }(egret.Sprite));
    battle.PlayerInfo = PlayerInfo;
    __reflect(PlayerInfo.prototype, "battle.PlayerInfo");
})(battle || (battle = {}));
/**
 * Created by Administrator on 2015/12/25.
 */
// 倒计时'闹钟'
var battle;
(function (battle) {
    var PlayerTime = (function (_super) {
        __extends(PlayerTime, _super);
        function PlayerTime() {
            var _this = _super.call(this) || this;
            _this._contain = null;
            _this._loc = 0;
            _this.PlayerTime = 25000;
            _this._bg = null;
            _this._startTime = 0;
            _this._alert = false;
            _this._flashTime = 0;
            _this._txt = null;
            return _this;
        }
        PlayerTime.prototype.Init = function () {
            this._contain = new egret.Sprite();
            this.addChild(this._contain);
            this._bg = new egret.Sprite();
            this._contain.addChild(this._bg);
            var bg = new egret.Bitmap(RES.getRes("ui_clock"));
            this._bg.addChild(bg);
            bg.x = 0;
            bg.y = 0;
            this._txt = new egret.TextField();
            this._txt.text = "";
            this._txt.width = 50;
            this._txt.textColor = 0xff0000;
            this._contain.addChild(this._txt);
            this._txt.textAlign = egret.HorizontalAlign.CENTER;
            this._txt.x = 12;
            this._txt.y = 23;
            this._alert = false;
            this._contain.visible = true;
        };
        PlayerTime.prototype.SetPoint = function (loc, delaytime) {
            if (loc == 1) {
                this.x = 60;
                this.y = 250;
            }
            else if (loc == 2) {
                this.x = 500;
                this.y = 250;
            }
            else if (loc == 3) {
                this.x = 147;
                this.y = 540;
            }
            this._loc = loc;
            this.PlayerTime = delaytime;
            this._startTime = egret.getTimer();
            this._alert = false;
            this._contain.visible = true;
            this._txt.text = "OK";
        };
        PlayerTime.prototype.Update = function () {
            var ntimer = egret.getTimer();
            var pstimer = ntimer - this._startTime;
            var progree = pstimer / this.PlayerTime;
            if (progree > 1) {
                progree = 1;
                //this._startTime = ntimer;
            }
            var hastime = Math.floor((this.PlayerTime - pstimer) / 1000);
            if (hastime < 0) {
                hastime = 0;
            }
            ;
            var hasstr = "" + hastime;
            if (hasstr != this._txt.text) {
                this._txt.text = hasstr;
            }
            if (this._loc != 3) {
                return;
            }
            if (progree > 0.5 && this._alert == false && this.visible) {
                this._alert = true;
                //SoundMgr.Instance.PlayEffect("alert_mp3");
            }
            if (this._alert) {
                if (hastime <= 0) {
                    this._contain.visible = true;
                }
                else if ((ntimer - this._flashTime) > PlayerTime.FlashDelay) {
                    this._flashTime = ntimer;
                    this._contain.visible = !this._contain.visible;
                }
            }
        };
        PlayerTime.prototype.Release = function () {
            if (this.parent) {
                this.parent.removeChild(this);
            }
        };
        PlayerTime.FlashDelay = 500; //闪动间隔
        return PlayerTime;
    }(egret.Sprite));
    battle.PlayerTime = PlayerTime;
    __reflect(PlayerTime.prototype, "battle.PlayerTime");
})(battle || (battle = {}));
/**
 * 发牌动画
 */
var battle;
(function (battle) {
    var SendCardAnimal = (function () {
        function SendCardAnimal() {
            this._sendLayer = null; //发牌的那一堆
            this._cardLayer = null;
            this._player = null;
            this._cardVlist = null;
            this._gameScene = null;
            this._overfun = null;
            this._overThis = null;
            this._timer1 = null;
            this._mCard1 = null;
            this._mCard2 = null;
            this._mCard3 = null;
        }
        SendCardAnimal.prototype.Init = function (gs) {
            this._gameScene = gs;
        };
        SendCardAnimal.prototype.StartAnimal = function (player, overfun, thisObj) {
            this._overfun = overfun;
            this._overThis = thisObj;
            this._player = player;
            this._cardVlist = [];
            this._sendLayer = new egret.Sprite();
            this._cardLayer = new egret.Sprite();
            this._gameScene.addChild(this._cardLayer);
            this._cardLayer.x = 0;
            this._cardLayer.y = Config.StageHeight - battle.MyCardControl.DOWNGAP - battle.CardUI.CARDHEIGHT * 2 - battle.MyCardControl.VERCARGAP;
            console.info("this._cardLayer.y ", this._cardLayer.y);
            this.sendCardAni();
        };
        //发牌
        SendCardAnimal.prototype.sendCardAni = function () {
            //中间发牌
            this._cardLayer.addChild(this._sendLayer);
            var i = 0;
            for (i = 0; i < 3; i++) {
                var card = MandPool.getInsByParm(battle.CardUI, 0);
                this._sendLayer.addChild(card);
                card.x = 220 + i * 10;
                card.y = -300;
            }
            this._mCard1 = MandPool.getInsByParm(battle.CardUI, 0);
            this._cardLayer.addChild(this._mCard1);
            this._mCard1.x = 250;
            this._mCard1.y = -300;
            this._mCard2 = MandPool.getInsByParm(battle.CardUI, 0);
            this._cardLayer.addChild(this._mCard2);
            this._mCard2.x = 250;
            this._mCard2.y = -300;
            this._mCard3 = MandPool.getInsByParm(battle.CardUI, 0);
            this._cardLayer.addChild(this._mCard3);
            this._mCard3.x = 250;
            this._mCard3.y = -300;
            egret.Tween.get(this._mCard1, { loop: true }).wait(0).to({ x: 0 }, 300).to({ x: 250 }, 0).wait(400);
            egret.Tween.get(this._mCard2, { loop: true }).wait(200).to({ x: 500 }, 300).to({ x: 250 }, 0).wait(200);
            egret.Tween.get(this._mCard3, { loop: true }).wait(400).to({ y: 0 }, 300).to({ y: 370 }, 0).wait(0);
            this._timer1 = new egret.Timer(220, 17);
            this._timer1.addEventListener(egret.TimerEvent.TIMER, this.onTimer, this);
            this._timer1.start();
        };
        SendCardAnimal.prototype.onTimer = function (e) {
            var ccount = this._timer1.currentCount;
            if (ccount == this._timer1.repeatCount) {
                egret.Tween.removeTweens(this._mCard1);
                egret.Tween.removeTweens(this._mCard2);
                egret.Tween.removeTweens(this._mCard3);
                // http://developer.egret.com/cn/apidoc/index/name/egret.TimerEvent#TIMER
                this.setCard(this._player.cardList);
                this._timer1.removeEventListener(egret.TimerEvent.TIMER, this.onTimer, this);
                this._timer1.stop();
                this._timer1 = null;
                this.showOwnerAni();
            }
            else {
                var arr = this._player.cardList.slice(0, ccount);
                this.setCard(arr);
            }
        };
        SendCardAnimal.prototype.showOwnerAni = function () {
            this._sendLayer.removeChildren();
            if (this._sendLayer.parent) {
                this._sendLayer.parent.removeChild(this._sendLayer);
                this._sendLayer = null;
            }
            this._mCard1.x = 250;
            this._mCard1.y = -300;
            this._mCard2.x = 250;
            this._mCard2.y = -300;
            this._mCard3.x = 250;
            this._mCard3.y = -300;
            egret.Tween.get(this._mCard1).to({ x: 50 }, 300);
            egret.Tween.get(this._mCard2).to({ x: 450 }, 300);
            this._overfun.call(this._overThis);
        };
        SendCardAnimal.prototype.setCard = function (cardlist) {
            var rlen = this._cardVlist.length;
            var ri = 0;
            for (ri = 0; ri < rlen; ri++) {
                var card = this._cardVlist[ri];
                card.Release();
            }
            this._cardVlist = [];
            var clist = cardlist;
            clist.sort(function (a, b) {
                if (a % 100 == b % 100) {
                    if (a > b) {
                        return 1;
                    }
                    else {
                        return -1;
                    }
                }
                else if (a % 100 > b % 100) {
                    return -1;
                }
                return 1;
            });
            var list = this.dividArr(cardlist);
            var list1 = list[0];
            var list2 = list[1];
            var len1 = list1.length;
            var len2 = list2.length;
            var dis = Config.StageWidth - battle.MyCardControl.LEFTGAP - battle.MyCardControl.RIGHTGAP - battle.CardUI.CARDWIDTH;
            var cy1 = 0; //Config.StageHeight-MyCardControl.DOWNGAP-CardUI.CARDHEIGHT;
            var cy2 = cy1 + battle.MyCardControl.VERCARGAP + battle.CardUI.CARDHEIGHT;
            var gap1 = dis / (len1 - 1);
            var gap2 = dis / (len2 - 1);
            var i = 0;
            if (gap1 > battle.MyCardControl.HORCARGAP) {
                gap1 = battle.MyCardControl.HORCARGAP;
            }
            if (gap2 > battle.MyCardControl.HORCARGAP) {
                gap2 = battle.MyCardControl.HORCARGAP;
            }
            var sx1 = (Config.StageWidth - (gap1 * (len1 - 1) + battle.CardUI.CARDWIDTH)) / 2;
            var sx2 = (Config.StageWidth - (gap2 * (len2 - 1) + battle.CardUI.CARDWIDTH)) / 2;
            for (i = 0; i < len1; i++) {
                var card = MandPool.getInsByParm(battle.CardUI, list1[i]);
                card.y = cy1;
                card.x = sx1 + i * gap1;
                this._cardLayer.addChild(card);
                this._cardVlist.push(card);
            }
            for (i = 0; i < len2; i++) {
                var card = MandPool.getInsByParm(battle.CardUI, list2[i]);
                card.y = cy2;
                card.x = sx2 + i * gap2;
                this._cardLayer.addChild(card);
                this._cardVlist.push(card);
            }
        };
        //划分为上下显示的两个数组
        SendCardAnimal.prototype.dividArr = function (cardlist) {
            var arr1 = [];
            var arr2 = [];
            var len = this._player.cardNumber;
            var i = 0;
            var cardvalue;
            //先分配到两个数组
            for (i = 0; i < 10; i++) {
                cardvalue = cardlist[i];
                if (cardvalue) {
                    arr1.push(cardvalue);
                }
            }
            for (i = 10; i < 20; i++) {
                cardvalue = cardlist[i];
                if (cardvalue) {
                    arr2.push(cardvalue);
                }
            }
            //检查第二个数组的第一个数字第一个数组中是否存在(同样数字应该在一列)
            var samevalue;
            if ((arr2[0])) {
                (arr2[0]).Value % 100;
            }
            var len1 = arr1.length;
            var len2 = arr2.length;
            var long = 0;
            if (samevalue) {
                for (i = len1 - 1; i >= 0; i--) {
                    if (samevalue == (arr1[i]).Value % 100) {
                        long++;
                        if (long + len2 < 10) {
                            arr2.unshift(arr1.pop());
                        }
                    }
                    else {
                        break;
                    }
                }
            }
            return [arr1, arr2];
        };
        //地主牌飞到指定位置
        SendCardAnimal.prototype.Release = function (loctid) {
            if (loctid == 0) {
                this._gameScene.removeChildren();
                return;
            }
            var tx = 20; //500;20;
            var ty = 100; //100;700;
            if (loctid == 1) {
                tx = 40;
                ty = -520;
            }
            else if (loctid == 2) {
                tx = 500;
                ty = -520;
            }
            else if (loctid == 3) {
                tx = 250;
                ty = 0;
            }
            if (this._mCard3) {
                egret.Tween.get(this._mCard3).to({ x: tx, y: ty }, 500).call(function () {
                    this._gameScene.removeChildren();
                }, this);
            }
            if (this._mCard2) {
                egret.Tween.get(this._mCard2).to({ x: tx, y: ty }, 500).call(function () {
                    this._gameScene.removeChildren();
                }, this);
            }
            if (this._mCard1) {
                egret.Tween.get(this._mCard1).to({ x: tx, y: ty }, 500).call(function () {
                    this._gameScene.removeChildren();
                }, this);
            }
        };
        return SendCardAnimal;
    }());
    battle.SendCardAnimal = SendCardAnimal;
    __reflect(SendCardAnimal.prototype, "battle.SendCardAnimal");
})(battle || (battle = {}));
var gameLogic;
(function (gameLogic) {
    var CardListData = (function () {
        function CardListData() {
            this.FromId = -1; //标记发牌玩家
            this.Type = gameLogic.PlayCardTypes.Types_Error;
            this.List = []; //原始数据数组,没有与100取余过
            this.AllArr = []; //数据数组,与100取余过
            this.OneArr = []; //所有的数字,只有一个,不会出现重复   与100取余过
            this.SingleArr = []; //数据数组,与100取余过
            this.DoubleArr = []; //数据数组,与100取余过
            this.TripleArr = []; //数据数组,与100取余过
            this.QuadrupleArr = []; //数据数组,与100取余过
        }
        CardListData.prototype.PlaySound = function () {
            var st = "";
            var num;
            var st2 = "_mp3";
            switch (this.Type) {
                case gameLogic.PlayCardTypes.Types_Error:
                    return;
                case gameLogic.PlayCardTypes.Types_Signal:
                    st = "woman_";
                    num = this.SingleArr[0];
                    break;
                case gameLogic.PlayCardTypes.Types_Double:
                    st = "woman_dui";
                    num = this.DoubleArr[0];
                    break;
                case gameLogic.PlayCardTypes.Types_Three:
                    st = "woman_sange";
                    break;
                case gameLogic.PlayCardTypes.Types_Three_Signal:
                    st = "woman_sandaiyi";
                    break;
                case gameLogic.PlayCardTypes.Types_Three_Double:
                    st = "woman_sandaiyidui";
                    break;
                case gameLogic.PlayCardTypes.Types_Four_Signal:
                    st = "woman_sidaier";
                    break;
                case gameLogic.PlayCardTypes.Types_Four_Double:
                    st = "woman_sidailiangdui";
                    break;
                case gameLogic.PlayCardTypes.Types_ThreeN:
                    st = "woman_feiji";
                    break;
                case gameLogic.PlayCardTypes.Types_ThreeN_Signal:
                    st = "woman_feiji";
                    break;
                case gameLogic.PlayCardTypes.Types_ThreeN_Double:
                    st = "woman_feiji";
                    break;
                case gameLogic.PlayCardTypes.Types_List:
                    st = "woman_shunzi";
                    break;
                case gameLogic.PlayCardTypes.Types_DoubleN:
                    st = "woman_liandui";
                    break;
                case gameLogic.PlayCardTypes.Types_Bomb:
                    st = "woman_zhadan";
                    if (this.List.length < 3) {
                        st = "woman_wangzha";
                    }
                    //SoundMgr.Instance.PlayEffect("bomb_mp3",true);
                    break;
                default:
                    break;
            }
            var url;
            if (num == null) {
                url = st + st2;
            }
            else {
                url = st + num + st2;
            }
            //SoundMgr.Instance.PlayEffect(url);
        };
        //获取大于等于某值的牌的数量
        CardListData.prototype.HasBigTo = function (num) {
            var len = this.List.length;
            var i = 0;
            var value;
            var barr = [];
            for (i = 0; i < len; i++) {
                value = this.List[i];
                if (value % 100 >= num) {
                    return true;
                }
            }
            return false;
        };
        CardListData.prototype.HasBomb = function () {
            if (this.getCountOfNum(98) > 0 && this.getCountOfNum(99) > 0) {
                return true;
            }
            if (this.QuadrupleArr.length > 0) {
                return true;
            }
            return false;
        };
        CardListData.prototype.getSingleValueExceptNum = function (numlist) {
            var len1 = this.AllArr.length;
            var len2 = numlist.length;
            var value;
            var barr = [];
            var i = 0;
            var j = 0;
            var has = false;
            for (i = 0; i < len1; i++) {
                value = this.OneArr[i];
                has = false;
                for (j = 0; j < len2; j++) {
                    if (value % 100 == (numlist[j]) % 100) {
                        has = true;
                    }
                }
                if (has == false) {
                    barr.push(value);
                }
            }
            return barr;
        };
        CardListData.prototype.getDoubleValueExceptNum = function (numlist) {
            var list = this.DoubleArr.concat(this.TripleArr);
            var len1 = list.length;
            var len2 = numlist.length;
            var value;
            var barr = [];
            var i = 0;
            var j = 0;
            var has = false;
            for (i = 0; i < len1; i++) {
                value = list[i];
                has = false;
                for (j = 0; j < len2; j++) {
                    if (value % 100 == (numlist[j]) % 100) {
                        has = true;
                    }
                }
                if (has == false) {
                    barr.push(value);
                }
            }
            return barr;
        };
        //根据卡牌数字得到100以上真实值
        CardListData.prototype.getValueByNum = function (num, count, type) {
            if (type === void 0) { type = false; }
            var len = this.List.length;
            var i = 0;
            var value;
            var barr = [];
            for (i = 0; i < len; i++) {
                value = this.List[i];
                if (type == false) {
                    if (value % 100 == num % 100) {
                        barr.push(value);
                        count--;
                        if (count <= 0) {
                            break;
                        }
                    }
                }
                else {
                    if (value == num) {
                        barr.push(value);
                        break;
                    }
                }
            }
            return barr;
        };
        CardListData.prototype.ContainList = function (hlist) {
            if (hlist == null || hlist.List == null || hlist.List.length < 1) {
                return false;
            }
            var barr = hlist.List;
            var len1 = this.List.length;
            var len2 = barr.length;
            var i = 0;
            var j = 0;
            var has = false;
            for (j = 0; j < len2; j++) {
                has = false;
                for (i = 0; i < len1; i++) {
                    if (barr[j] == this.List[i]) {
                        has = true;
                    }
                }
                if (has == false) {
                    return false;
                }
            }
            return true;
        };
        /**
         * 根据卡牌数字得到数量,几个3,几个2之类的
         * @param num
         */
        CardListData.prototype.getCountOfNum = function (num) {
            num = num % 100;
            var len = this.AllArr.length;
            var i = 0;
            var count = 0;
            for (i = 0; i < len; i++) {
                if (this.AllArr[i] == num) {
                    count++;
                }
            }
            return count;
        };
        return CardListData;
    }());
    gameLogic.CardListData = CardListData;
    __reflect(CardListData.prototype, "gameLogic.CardListData");
})(gameLogic || (gameLogic = {}));
var gameLogic;
(function (gameLogic) {
    var Compare = (function () {
        function Compare() {
        }
        Compare.prototype.IsBiger = function (cld1, cld2) {
            if (cld2 == null) {
                //console.info("Compare-IsBiger> 没有桌面牌");
                return true;
            }
            if (cld1.Type != cld2.Type && cld1.Type != gameLogic.PlayCardTypes.Types_Bomb) {
                //console.info("Compare-IsBiger> 类型出错");
                return false;
            }
            switch (cld1.Type) {
                case gameLogic.PlayCardTypes.Types_Signal:
                    return this.compareSigle(cld1, cld2);
                case gameLogic.PlayCardTypes.Types_Double:
                    return this.compareDouble(cld1, cld2);
                case gameLogic.PlayCardTypes.Types_Three:
                case gameLogic.PlayCardTypes.Types_Three_Signal:
                case gameLogic.PlayCardTypes.Types_Three_Double:
                    return this.compareThree(cld1, cld2);
                case gameLogic.PlayCardTypes.Types_Four_Double:
                case gameLogic.PlayCardTypes.Types_Four_Signal:
                    return this.compareFour(cld1, cld2);
                case gameLogic.PlayCardTypes.Types_ThreeN:
                case gameLogic.PlayCardTypes.Types_ThreeN_Signal:
                case gameLogic.PlayCardTypes.Types_ThreeN_Double:
                    return this.compareThreeN(cld1, cld2);
                case gameLogic.PlayCardTypes.Types_List:
                    return this.compareList(cld1, cld2);
                case gameLogic.PlayCardTypes.Types_DoubleN:
                    return this.compareDoubleN(cld1, cld2);
                case gameLogic.PlayCardTypes.Types_Bomb:
                    return this.compareBomb(cld1, cld2);
                default:
                    break;
            }
        };
        //比较炸弹
        Compare.prototype.compareBomb = function (cld1, cld2) {
            if (cld2.Type != gameLogic.PlayCardTypes.Types_Bomb) {
                return true;
            }
            var num1;
            var num2;
            var len1 = cld1.QuadrupleArr.length;
            var len2 = cld2.QuadrupleArr.length;
            if (len1 == 0) {
                return true;
            }
            if (len2 == 0) {
                //console.info("Compare-IsBiger> 不能大过王炸");
                return false;
            }
            num1 = cld1.QuadrupleArr[0];
            num2 = cld2.QuadrupleArr[0];
            if (num1 > num2) {
                return true;
            }
            else {
                return false;
            }
        };
        //比较连对
        Compare.prototype.compareDoubleN = function (cld1, cld2) {
            var num1;
            var num2;
            var len1 = cld1.DoubleArr.length;
            var len2 = cld2.DoubleArr.length;
            if (len1 != len2) {
                //console.info("Compare-IsBiger> 连对数量不匹配");
                return false;
            }
            num1 = cld1.DoubleArr[0];
            num2 = cld2.DoubleArr[0];
            if (num1 > num2) {
                return true;
            }
            else {
                return false;
            }
        };
        //比较顺子
        Compare.prototype.compareList = function (cld1, cld2) {
            var num1;
            var num2;
            var len1 = cld1.SingleArr.length;
            var len2 = cld2.SingleArr.length;
            if (len1 != len2) {
                //console.info("Compare-IsBiger> 顺子数量不匹配");
                return false;
            }
            num1 = cld1.SingleArr[0];
            num2 = cld2.SingleArr[0];
            if (num1 > num2) {
                return true;
            }
            else {
                return false;
            }
        };
        //比较飞机
        Compare.prototype.compareThreeN = function (cld1, cld2) {
            var num1;
            var num2;
            var len1 = cld1.TripleArr.length;
            var len2 = cld2.TripleArr.length;
            if (len1 != len2) {
                //console.info("Compare-IsBiger> 飞机数量不匹配");
                return false;
            }
            num1 = cld1.TripleArr[0];
            num2 = cld2.TripleArr[0];
            if (num1 > num2) {
                return true;
            }
            else {
                return false;
            }
        };
        //四张比较
        Compare.prototype.compareFour = function (cld1, cld2) {
            var num1;
            var num2;
            num1 = cld1.QuadrupleArr[0];
            num2 = cld2.QuadrupleArr[0];
            if (num1 > num2) {
                return true;
            }
            else {
                return false;
            }
        };
        //三张比较
        Compare.prototype.compareThree = function (cld1, cld2) {
            var num1;
            var num2;
            num1 = cld1.TripleArr[0];
            num2 = cld2.TripleArr[0];
            if (num1 > num2) {
                return true;
            }
            else {
                return false;
            }
        };
        //对子比较
        Compare.prototype.compareDouble = function (cld1, cld2) {
            var num1;
            var num2;
            num1 = cld1.DoubleArr[0];
            num2 = cld2.DoubleArr[0];
            if (num1 > num2) {
                return true;
            }
            else {
                return false;
            }
        };
        //单张比较
        Compare.prototype.compareSigle = function (cld1, cld2) {
            var num1;
            var num2;
            num1 = cld1.SingleArr[0];
            num2 = cld2.SingleArr[0];
            if (num1 > num2) {
                return true;
            }
            else {
                return false;
            }
        };
        return Compare;
    }());
    gameLogic.Compare = Compare;
    __reflect(Compare.prototype, "gameLogic.Compare");
})(gameLogic || (gameLogic = {}));
var gameLogic;
(function (gameLogic) {
    var PlayCardTypes = (function () {
        function PlayCardTypes() {
            this._cardsAll = [];
            this._singleArr = [];
            this._doubleArr = [];
            this._tripleArr = [];
            this._quadrupleArr = [];
        }
        PlayCardTypes.prototype.GetType = function (list) {
            if (list == null || list.length < 1) {
                return new gameLogic.CardListData();
            }
            this._cardsAll = [];
            this._singleArr = [];
            this._doubleArr = [];
            this._tripleArr = [];
            this._quadrupleArr = [];
            var i = 0;
            var len = list.length;
            var cardlistdata = new gameLogic.CardListData();
            for (i = 0; i < len; i++) {
                this._cardsAll.push(list[i] % 100);
            }
            //随机排序一下
            this._cardsAll.sort(function sortNumber(a, b) {
                return a - b;
            });
            this.divid();
            var alllen = this._cardsAll.length;
            var siglelen = this._singleArr.length;
            var doublelen = this._doubleArr.length;
            var triplelen = this._tripleArr.length;
            var quadruplen = this._quadrupleArr.length;
            cardlistdata.List = list;
            cardlistdata.AllArr = this._cardsAll;
            cardlistdata.SingleArr = this._singleArr;
            cardlistdata.DoubleArr = this._doubleArr;
            cardlistdata.TripleArr = this._tripleArr;
            cardlistdata.QuadrupleArr = this._quadrupleArr;
            cardlistdata.OneArr = this._singleArr.concat(this._doubleArr).concat(this._tripleArr).concat(this._quadrupleArr);
            ArrayTools.Sort(cardlistdata.OneArr);
            var isfly = true; //飞机
            var islist = true; //顺子
            var isdoublist = true; //连对
            var last = -1;
            var num = 0;
            if (alllen == 1) {
                console.info("Types-GetType> 一张");
                cardlistdata.Type = PlayCardTypes.Types_Signal;
                return cardlistdata;
            }
            if (alllen == 2 && doublelen == 1) {
                console.info("Types-GetType> 一对");
                cardlistdata.Type = PlayCardTypes.Types_Double;
                return cardlistdata;
            }
            if (alllen == 3 && triplelen == 1) {
                console.info("Types-GetType> 三张");
                cardlistdata.Type = PlayCardTypes.Types_Three;
                return cardlistdata;
            }
            if (alllen == 4 && triplelen == 1) {
                console.info("Types-GetType> 三带一");
                cardlistdata.Type = PlayCardTypes.Types_Three_Signal;
                return cardlistdata;
            }
            if (alllen == 5 && triplelen == 1 && doublelen == 1) {
                console.info("Types-GetType> 三代一对");
                cardlistdata.Type = PlayCardTypes.Types_Three_Double;
                return cardlistdata;
            }
            if (alllen == 6 && quadruplen == 1 && siglelen == 2) {
                console.info("Types-GetType> 四带二");
                cardlistdata.Type = PlayCardTypes.Types_Four_Signal; //4带二,大小王先不算,欢乐斗地主不能带牌
                return cardlistdata;
            }
            if (alllen == 6 && quadruplen == 1 && doublelen == 1) {
                console.info("Types-GetType> 四带二");
                cardlistdata.Type = PlayCardTypes.Types_Four_Signal; //4带二,大小王先不算,欢乐斗地主不能带牌
                return cardlistdata;
            }
            if (alllen == 8 && quadruplen == 1 && doublelen == 2) {
                console.info("Types-GetType> 四带两对");
                cardlistdata.Type = PlayCardTypes.Types_Four_Double; //4带二对,大小王先不算,欢乐斗地主不能带牌
                return cardlistdata;
            }
            if (triplelen > 1 && quadruplen == 0) {
                isfly = true;
                last = -1;
                for (i = 0; i < triplelen; i++) {
                    num = this._tripleArr[i];
                    if (last == -1) {
                        last = num;
                    }
                    else if (num == (last + 1)) {
                        last = num;
                    }
                    else {
                        isfly = false;
                    }
                }
                //是飞机状况
                if (isfly) {
                    //飞机不带牌
                    if (siglelen == 0 && doublelen == 0 && quadruplen == 0) {
                        console.info("Types-GetType> 飞机");
                        cardlistdata.Type = PlayCardTypes.Types_ThreeN;
                        return cardlistdata;
                    }
                    //飞机带双牌
                    if (triplelen == doublelen && siglelen == 0 && quadruplen == 0) {
                        console.info("Types-GetType> 飞机带对子");
                        cardlistdata.Type = PlayCardTypes.Types_ThreeN_Double;
                        return cardlistdata;
                    }
                    //飞机带单牌
                    if (triplelen == siglelen && doublelen == 0 && quadruplen == 0 ||
                        triplelen == (siglelen + doublelen * 2) && quadruplen == 0) {
                        console.info("Types-GetType> 飞机带单牌");
                        cardlistdata.Type = PlayCardTypes.Types_ThreeN_Signal;
                        return cardlistdata;
                    }
                }
            }
            if (doublelen == 0 && triplelen == 0 && quadruplen == 0 && siglelen > 4) {
                islist = true;
                last = -1;
                for (i = 0; i < siglelen; i++) {
                    num = this._singleArr[i];
                    if (last == -1) {
                        last = num;
                    }
                    else if (num == (last + 1)) {
                        last = num;
                    }
                    else {
                        islist = false;
                    }
                }
                if (islist) {
                    console.info("Types-GetType> 顺子");
                    cardlistdata.Type = PlayCardTypes.Types_List;
                    return cardlistdata;
                }
            }
            if (doublelen > 2 && triplelen == 0 && quadruplen == 0 && siglelen == 0) {
                isdoublist = true;
                last = -1;
                for (i = 0; i < doublelen; i++) {
                    num = this._doubleArr[i];
                    if (last == -1) {
                        last = num;
                    }
                    else if (num == (last + 1)) {
                        last = num;
                    }
                    else {
                        isdoublist = false;
                    }
                }
                if (isdoublist) {
                    console.info("Types-GetType> 连对");
                    cardlistdata.Type = PlayCardTypes.Types_DoubleN;
                    return cardlistdata;
                }
            }
            if (alllen == 4 && quadruplen == 1) {
                console.info("Types-GetType> 炸弹");
                cardlistdata.Type = PlayCardTypes.Types_Bomb; //普通炸弹
                return cardlistdata;
            }
            if (alllen == 2 && siglelen == 2) {
                if (this._singleArr[0] > 50 && this._singleArr[1] > 50) {
                    console.info("Types-GetType> 王炸");
                    cardlistdata.Type = PlayCardTypes.Types_Bomb; //王炸
                    return cardlistdata;
                }
            }
            cardlistdata.Type = PlayCardTypes.Types_Error;
            return cardlistdata;
        };
        //把取余后的列表划分到各个数组中
        PlayCardTypes.prototype.divid = function () {
            var i = 0;
            var len = this._cardsAll.length;
            for (i = 0; i < this._cardsAll.length; i++) {
                var id = this._cardsAll[i];
                var rePeat = this.NumberOf(id);
                switch (rePeat) {
                    case 1:
                        this._singleArr.push(id);
                        break;
                    case 2:
                        this._doubleArr.push(id);
                        i += 1;
                        break;
                    case 3:
                        this._tripleArr.push(id);
                        i += 2;
                        break;
                    case 4:
                        this._quadrupleArr.push(id);
                        i += 3;
                        break;
                    default:
                        break;
                }
            }
        };
        //计算数量
        PlayCardTypes.prototype.NumberOf = function (value) {
            var tid = value;
            var totalRepeat = 0;
            var i = 0;
            var len = this._cardsAll.length;
            for (i = 0; i < len; i++) {
                var id = this._cardsAll[i];
                if (id % 100 == tid) {
                    totalRepeat += 1;
                }
            }
            return totalRepeat;
        };
        PlayCardTypes.Types_Error = 0; //类型出错
        PlayCardTypes.Types_Signal = 1; //单张
        PlayCardTypes.Types_Double = 2; //一对
        PlayCardTypes.Types_Three = 3; //三个不带
        PlayCardTypes.Types_Three_Signal = 4; //三代1
        PlayCardTypes.Types_Three_Double = 5; //三带一对
        PlayCardTypes.Types_Four_Signal = 6; //四张带2张单牌
        PlayCardTypes.Types_Four_Double = 7; //四张带2对
        PlayCardTypes.Types_ThreeN = 8; //飞机不带
        PlayCardTypes.Types_ThreeN_Signal = 9; //飞机带单牌
        PlayCardTypes.Types_ThreeN_Double = 10; //飞机带双牌
        PlayCardTypes.Types_List = 11; //顺子
        PlayCardTypes.Types_DoubleN = 12; //连对
        PlayCardTypes.Types_Bomb = 13; //炸弹
        return PlayCardTypes;
    }());
    gameLogic.PlayCardTypes = PlayCardTypes;
    __reflect(PlayCardTypes.prototype, "gameLogic.PlayCardTypes");
})(gameLogic || (gameLogic = {}));
var gameLogic;
(function (gameLogic) {
    //提示类,智能提示
    var Prompt = (function () {
        function Prompt() {
            this._types = new gameLogic.PlayCardTypes();
            this._types = new gameLogic.PlayCardTypes();
        }
        /**
         * 选择最优牌
         * @param mylist 玩家自己的手牌
         * @param tableList 桌上牌,
         * @param enemycount 敌人的手牌数量
         * @param teamcount 队友的手牌数量
         * @constructor
         */
        Prompt.prototype.GetPrompt = function (mylist, tableList, enemycount, teamcount, nextIsteam, lastIsTeam) {
            if (tableList == null) {
                return this.getbest(mylist, enemycount, teamcount, nextIsteam);
            }
            else {
                var cld = this.getMinListByType(mylist, tableList.Type, tableList);
                if (cld != null && mylist.List.length - cld.List.length > 2 && lastIsTeam) {
                    if (cld.Type == gameLogic.PlayCardTypes.Types_Signal) {
                        if (cld.SingleArr[0] > 14) {
                            return null;
                        }
                    }
                    else if (cld.Type == gameLogic.PlayCardTypes.Types_Double) {
                        if (cld.DoubleArr[0] > 14) {
                            return null;
                        }
                    }
                    else if (cld.Type == gameLogic.PlayCardTypes.Types_Bomb) {
                        return null;
                    }
                }
                return cld;
            }
        };
        Prompt.prototype.GetPromptContain = function (mylist, tableList) {
            if (mylist.ContainList(tableList) == false) {
                return null;
            }
            var sl = [103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114];
            var cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
            if (cld == null || cld.ContainList(tableList) == false) {
                sl = [104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114];
                cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                if (cld == null || cld.ContainList(tableList) == false) {
                    sl = [103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113];
                    cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                    if (cld == null || cld.ContainList(tableList) == false) {
                        sl = [105, 106, 107, 108, 109, 110, 111, 112, 113, 114];
                        cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                        if (cld == null || cld.ContainList(tableList) == false) {
                            sl = [103, 104, 105, 106, 107, 108, 109, 110, 111, 112];
                            cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                            if (cld == null || cld.ContainList(tableList) == false) {
                                sl = [106, 107, 108, 109, 110, 111, 112, 113, 114];
                                cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                if (cld == null || cld.ContainList(tableList) == false) {
                                    sl = [107, 108, 109, 110, 111, 112, 113, 114];
                                    cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                    if (cld == null || cld.ContainList(tableList) == false) {
                                        sl = [103, 104, 105, 106, 107, 108, 109, 110, 111];
                                        cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                        if (cld == null || cld.ContainList(tableList) == false) {
                                            sl = [103, 104, 105, 106, 107, 108, 109, 110];
                                            cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                            if (cld == null || cld.ContainList(tableList) == false) {
                                                sl = [108, 109, 110, 111, 112, 113, 114];
                                                cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                                if (cld == null || cld.ContainList(tableList) == false) {
                                                    sl = [103, 104, 105, 106, 107, 108, 109];
                                                    cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                                    if (cld == null || cld.ContainList(tableList) == false) {
                                                        sl = [109, 110, 111, 112, 113, 114];
                                                        cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                                        if (cld == null || cld.ContainList(tableList) == false) {
                                                            sl = [103, 104, 105, 106, 107, 108];
                                                            cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                                            if (cld == null || cld.ContainList(tableList) == false) {
                                                                sl = [110, 111, 112, 113, 114];
                                                                cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                                                if (cld == null || cld.ContainList(tableList) == false) {
                                                                    sl = [109, 110, 111, 112, 113];
                                                                    cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                                                    if (cld == null || cld.ContainList(tableList) == false) {
                                                                        sl = [108, 109, 110, 111, 112];
                                                                        cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                                                        if (cld == null || cld.ContainList(tableList) == false) {
                                                                            sl = [107, 108, 109, 110, 111];
                                                                            cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                                                            if (cld == null || cld.ContainList(tableList) == false) {
                                                                                sl = [106, 107, 108, 109, 110];
                                                                                cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                                                                if (cld == null || cld.ContainList(tableList) == false) {
                                                                                    sl = [105, 106, 107, 108, 109];
                                                                                    cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                                                                    if (cld == null || cld.ContainList(tableList) == false) {
                                                                                        sl = [104, 105, 106, 107, 108];
                                                                                        cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                                                                        if (cld == null || cld.ContainList(tableList) == false) {
                                                                                            sl = [103, 104, 105, 106, 107];
                                                                                            cld = this.getContainList(mylist, this._types.GetType(sl), tableList.List);
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (cld == null || cld.ContainList(tableList) == false) {
                return null;
            }
            return cld;
        };
        Prompt.prototype.getContainList = function (mylist, tolist, mustlist) {
            var fromlist = mylist.OneArr;
            var len = fromlist.length;
            if (len < 5) {
                return null;
            }
            var minvalue = 0;
            var tolen = 0; //顺子长度
            var tomax = 12; //顺子最大长度
            if (tolist) {
                minvalue = tolist.SingleArr[0];
                tolen = tolist.SingleArr.length;
            }
            var i = 0;
            var j = 0;
            var value = 0;
            var maxnum = 0;
            var maxlcount = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value < minvalue) {
                    continue;
                }
                if (tolist) {
                    for (j = 0; j < tolen; j++) {
                        var nvalue = value + j;
                        var count = mylist.getCountOfNum(nvalue);
                        if (count < 1 || count > 3) {
                            break;
                        }
                        if (j == tolen - 1) {
                            maxnum = nvalue;
                        }
                    }
                    if (maxnum != 0) {
                        break;
                    }
                }
            }
            if (maxnum == 0) {
                return null;
            }
            var value2 = [];
            var getArr;
            var mustlen = mustlist.length;
            for (i = 0; i < tolen; i++) {
                var ccvalue = maxnum - i;
                var istype = false;
                for (j = 0; j < mustlen; j++) {
                    if (mustlist[j] % 100 == ccvalue) {
                        ccvalue = mustlist[j];
                        istype = true;
                    }
                }
                getArr = mylist.getValueByNum(ccvalue, 1, istype);
                value2 = value2.concat(getArr);
            }
            var cld = this._types.GetType(value2);
            return cld;
        };
        /**
         * 没有类型限制的时候获取最好的牌
         * @param mylist      自己的手牌
         * @param enemycount    敌人手牌数量
         * @param teamcount     队伍手牌数量
         * @returns {null}
         */
        Prompt.prototype.getbest = function (mylist, enemycount, teamcount, nextIsenemy) {
            //优先级列表
            var frontTypeList = [
                gameLogic.PlayCardTypes.Types_ThreeN_Signal,
                gameLogic.PlayCardTypes.Types_ThreeN_Double,
                gameLogic.PlayCardTypes.Types_ThreeN,
                gameLogic.PlayCardTypes.Types_DoubleN,
                gameLogic.PlayCardTypes.Types_List,
                gameLogic.PlayCardTypes.Types_Three_Signal,
                gameLogic.PlayCardTypes.Types_Three_Double,
                gameLogic.PlayCardTypes.Types_Three,
                gameLogic.PlayCardTypes.Types_Double,
                gameLogic.PlayCardTypes.Types_Signal,
                //Types.Types_Four_Signal,
                //Types.Types_Four_Double,
                gameLogic.PlayCardTypes.Types_Bomb
            ];
            if (nextIsenemy) {
                if (enemycount == 1) {
                    frontTypeList = [
                        gameLogic.PlayCardTypes.Types_ThreeN_Signal,
                        gameLogic.PlayCardTypes.Types_ThreeN_Double,
                        gameLogic.PlayCardTypes.Types_ThreeN,
                        gameLogic.PlayCardTypes.Types_DoubleN,
                        gameLogic.PlayCardTypes.Types_List,
                        gameLogic.PlayCardTypes.Types_Three_Signal,
                        gameLogic.PlayCardTypes.Types_Three_Double,
                        gameLogic.PlayCardTypes.Types_Three,
                        gameLogic.PlayCardTypes.Types_Double,
                        //Types.Types_Four_Signal,
                        //Types.Types_Four_Double,
                        gameLogic.PlayCardTypes.Types_Bomb,
                        gameLogic.PlayCardTypes.Types_Signal
                    ];
                }
                else if (enemycount == 2) {
                    frontTypeList = [
                        gameLogic.PlayCardTypes.Types_ThreeN_Signal,
                        gameLogic.PlayCardTypes.Types_ThreeN_Double,
                        gameLogic.PlayCardTypes.Types_ThreeN,
                        gameLogic.PlayCardTypes.Types_DoubleN,
                        gameLogic.PlayCardTypes.Types_List,
                        gameLogic.PlayCardTypes.Types_Three_Signal,
                        gameLogic.PlayCardTypes.Types_Three_Double,
                        gameLogic.PlayCardTypes.Types_Three,
                        gameLogic.PlayCardTypes.Types_Signal,
                        //Types.Types_Four_Signal,
                        //Types.Types_Four_Double,
                        gameLogic.PlayCardTypes.Types_Bomb,
                        gameLogic.PlayCardTypes.Types_Double
                    ];
                }
            }
            else {
                if (teamcount == 1) {
                    frontTypeList = [
                        gameLogic.PlayCardTypes.Types_Signal,
                        gameLogic.PlayCardTypes.Types_ThreeN_Signal,
                        gameLogic.PlayCardTypes.Types_ThreeN_Double,
                        gameLogic.PlayCardTypes.Types_ThreeN,
                        gameLogic.PlayCardTypes.Types_DoubleN,
                        gameLogic.PlayCardTypes.Types_List,
                        gameLogic.PlayCardTypes.Types_Three_Signal,
                        gameLogic.PlayCardTypes.Types_Three_Double,
                        gameLogic.PlayCardTypes.Types_Three,
                        gameLogic.PlayCardTypes.Types_Double,
                        //Types.Types_Four_Signal,
                        //Types.Types_Four_Double,
                        gameLogic.PlayCardTypes.Types_Bomb
                    ];
                }
                else if (enemycount == 2) {
                    frontTypeList = [
                        gameLogic.PlayCardTypes.Types_Double,
                        gameLogic.PlayCardTypes.Types_ThreeN_Signal,
                        gameLogic.PlayCardTypes.Types_ThreeN_Double,
                        gameLogic.PlayCardTypes.Types_ThreeN,
                        gameLogic.PlayCardTypes.Types_DoubleN,
                        gameLogic.PlayCardTypes.Types_List,
                        gameLogic.PlayCardTypes.Types_Three_Signal,
                        gameLogic.PlayCardTypes.Types_Three_Double,
                        gameLogic.PlayCardTypes.Types_Three,
                        gameLogic.PlayCardTypes.Types_Signal,
                        //Types.Types_Four_Signal,
                        //Types.Types_Four_Double,
                        gameLogic.PlayCardTypes.Types_Bomb
                    ];
                }
            }
            var i = 0;
            var len = frontTypeList.length;
            var type = 0;
            var tolist = null;
            for (i = 0; i < len; i++) {
                type = frontTypeList[i];
                var cd = this.getMinListByType(mylist, type);
                if (cd != null) {
                    return cd;
                }
            }
            return null;
        };
        /**
         * 从小到大获取提示
         *
         * @param mylist
         *            玩家手牌
         * @param type
         *            类型
         * @param tolist
         *            =null 桌面牌,没有桌面牌从小到大选择一张
         * @return
         */
        Prompt.prototype.getMinListByType = function (mylist, type, tolist) {
            switch (type) {
                case gameLogic.PlayCardTypes.Types_Signal:
                    var slist = null;
                    if (tolist == null) {
                        slist = this.getSigleMaxEM(mylist);
                    }
                    if (slist) {
                        return slist;
                    }
                    else {
                        return this.getSigle(mylist, tolist);
                    }
                case gameLogic.PlayCardTypes.Types_Double:
                    return this.getDouble(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_Three:
                    return this.getThree(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_Three_Signal:
                    return this.getThree_Signal(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_Three_Double:
                    return this.getThree_Double(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_Four_Double:
                    return this.getBomb(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_Four_Signal:
                    return this.getBomb(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_ThreeN:
                    return this.getThreeN(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_ThreeN_Signal:
                    return this.getThreeN_Signal(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_ThreeN_Double:
                    return this.getThreeN_Double(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_List:
                    return this.getList(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_DoubleN:
                    return this.getDoubleN(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_Bomb:
                    return this.getBomb(mylist, tolist);
                default:
                    break;
            }
        };
        /**
         * 获取炸弹
         * @param tolist
         * @returns {any}
         */
        Prompt.prototype.getBomb = function (mylist, tolist) {
            var fromlist = mylist.QuadrupleArr;
            var bigkingcount = mylist.getCountOfNum(99);
            var tinykingcount = mylist.getCountOfNum(98);
            var len = fromlist.length;
            if (len < 1 && (bigkingcount < 1 || tinykingcount < 1) || (tolist && tolist.AllArr.length == 2)) {
                return null;
            }
            var minvalue = 0;
            if (tolist) {
                minvalue = tolist.QuadrupleArr[0];
            }
            var i = 0;
            var value = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value > minvalue) {
                    break;
                }
                value = 0;
            }
            if (value > 0) {
                var value2 = mylist.getValueByNum(value, 4);
                var cld = this._types.GetType(value2);
                return cld;
            }
            else if (bigkingcount > 0 && tinykingcount > 0) {
                var king1 = mylist.getValueByNum(98, 1);
                var king2 = mylist.getValueByNum(99, 1);
                var kingbomb = king1.concat(king2);
                var cld = this._types.GetType(kingbomb);
                return cld;
            }
            return null;
        };
        /**
         * 获取连对牌
         * @param tolist
         * @returns {any}
         */
        Prompt.prototype.getDoubleN = function (mylist, tolist) {
            var fromlist = mylist.DoubleArr;
            var len = fromlist.length;
            if (len < 3) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            var tolen = 0; //连对长度
            var tomax = 10; //连对最大长度
            if (tolist) {
                minvalue = tolist.DoubleArr[0];
                tolen = tolist.DoubleArr.length;
            }
            var i = 0;
            var j = 0;
            var value = 0;
            var maxnum = 0;
            var maxlcount = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value <= minvalue) {
                    continue;
                }
                if (tolist) {
                    for (j = 0; j < tolen; j++) {
                        var nvalue = value + j;
                        var count = mylist.getCountOfNum(nvalue);
                        if (count < 2 || count > 3) {
                            break;
                        }
                        if (j == tolen - 1) {
                            maxnum = nvalue;
                        }
                    }
                    if (maxnum != 0) {
                        break;
                    }
                }
                else {
                    for (j = 0; j < tomax; j++) {
                        var nvalue = value + j;
                        var count = mylist.getCountOfNum(nvalue);
                        if (count < 2 || count > 3) {
                            break;
                        }
                        else {
                            tolen++;
                            if (tolen > 2 && tolen > maxlcount) {
                                maxlcount = tolen;
                                maxnum = nvalue;
                            }
                        }
                    }
                    if (i >= len - 1) {
                        tolen = maxlcount;
                    }
                    else {
                        tolen = 0;
                    }
                }
            }
            if (maxnum == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var value2 = [];
            var getArr;
            for (i = 0; i < tolen; i++) {
                getArr = mylist.getValueByNum(maxnum - i, 2);
                value2 = value2.concat(getArr);
            }
            var cld = this._types.GetType(value2);
            return cld;
        };
        Prompt.prototype.getList = function (mylist, tolist) {
            var fromlist = mylist.OneArr;
            var len = fromlist.length;
            if (len < 5) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            var tolen = 0; //顺子长度
            var tomax = 12; //顺子最大长度
            if (tolist) {
                minvalue = tolist.SingleArr[0];
                tolen = tolist.SingleArr.length;
            }
            var i = 0;
            var j = 0;
            var value = 0;
            var maxnum = 0;
            var maxlcount = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value <= minvalue) {
                    continue;
                }
                if (tolist) {
                    for (j = 0; j < tolen; j++) {
                        var nvalue = value + j;
                        var count = mylist.getCountOfNum(nvalue);
                        if (count < 1 || count > 3) {
                            break;
                        }
                        if (j == tolen - 1) {
                            maxnum = nvalue;
                        }
                    }
                    if (maxnum != 0) {
                        break;
                    }
                }
                else {
                    for (j = 0; j < tomax; j++) {
                        var nvalue = value + j;
                        var count = mylist.getCountOfNum(nvalue);
                        if (count < 1 || count > 3) {
                            break;
                        }
                        else {
                            tolen++;
                            if (tolen > 4 && tolen > maxlcount) {
                                maxlcount = tolen;
                                maxnum = nvalue;
                            }
                        }
                    }
                    if (i >= len - 1) {
                        tolen = maxlcount;
                    }
                    else {
                        tolen = 0;
                    }
                }
            }
            if (maxnum == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var value2 = [];
            var getArr;
            for (i = 0; i < tolen; i++) {
                getArr = mylist.getValueByNum(maxnum - i, 1);
                value2 = value2.concat(getArr);
            }
            var cld = this._types.GetType(value2);
            return cld;
        };
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt.prototype.getThreeN_Signal = function (mylist, tolist) {
            var fromlist = mylist.TripleArr;
            var len = fromlist.length;
            if (len < 2) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            var tolen = 2; //飞机长度
            if (tolist) {
                minvalue = tolist.TripleArr[0];
                tolen = tolist.TripleArr.length;
            }
            if (len < tolen) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var i = 0;
            var j = 0;
            var value = 0;
            var maxnum = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value <= minvalue) {
                    continue;
                }
                for (j = 0; j < tolen; j++) {
                    var nvalue = value + j;
                    var count = mylist.getCountOfNum(nvalue);
                    if (count < 3) {
                        break;
                    }
                    if (j == tolen - 1) {
                        maxnum = nvalue;
                    }
                }
                if (maxnum != 0) {
                    break;
                }
            }
            if (maxnum == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var sign1;
            var sign2;
            if (mylist.SingleArr.length > 1) {
                sign1 = mylist.SingleArr[0];
                sign2 = mylist.SingleArr[1];
            }
            else {
                //没有单牌和对子就不提示了.
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var signArr1 = mylist.getValueByNum(sign1, 2);
            var signArr2 = mylist.getValueByNum(sign2, 2);
            var value2 = [];
            var getArr;
            for (i = 0; i < tolen; i++) {
                getArr = mylist.getValueByNum(maxnum - i, 3);
                value2 = value2.concat(getArr);
            }
            value2 = value2.concat(signArr1);
            value2 = value2.concat(signArr2);
            var cld = this._types.GetType(value2);
            return cld;
        };
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt.prototype.getThreeN_Double = function (mylist, tolist) {
            var fromlist = mylist.TripleArr;
            var len = fromlist.length;
            if (len < 2) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            var tolen = 2; //飞机长度
            if (tolist) {
                minvalue = tolist.TripleArr[0];
                tolen = tolist.TripleArr.length;
            }
            if (len < tolen) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var i = 0;
            var j = 0;
            var value = 0;
            var maxnum = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value <= minvalue) {
                    continue;
                }
                for (j = 0; j < tolen; j++) {
                    var nvalue = value + j;
                    var count = mylist.getCountOfNum(nvalue);
                    if (count < 3) {
                        break;
                    }
                    if (j == tolen - 1) {
                        maxnum = nvalue;
                    }
                }
                if (maxnum != 0) {
                    break;
                }
            }
            if (maxnum == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var sign1;
            var sign2;
            if (mylist.DoubleArr.length > 1) {
                sign1 = mylist.DoubleArr[0];
                sign2 = mylist.DoubleArr[1];
            }
            else {
                //没有单牌和对子就不提示了.
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var signArr1 = mylist.getValueByNum(sign1, 2);
            var signArr2 = mylist.getValueByNum(sign2, 2);
            var value2 = [];
            var getArr;
            for (i = 0; i < tolen; i++) {
                getArr = mylist.getValueByNum(maxnum - i, 3);
                value2 = value2.concat(getArr);
            }
            value2 = value2.concat(signArr1);
            value2 = value2.concat(signArr2);
            var cld = this._types.GetType(value2);
            return cld;
        };
        /**
         * 获取飞机牌
         * @param tolist
         * @returns {any}
         */
        Prompt.prototype.getThreeN = function (mylist, tolist) {
            var fromlist = mylist.TripleArr;
            var len = fromlist.length;
            if (len < 2) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            var tolen = 2; //飞机长度
            if (tolist) {
                minvalue = tolist.TripleArr[0];
                tolen = tolist.TripleArr.length;
            }
            if (len < tolen) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var i = 0;
            var j = 0;
            var value = 0;
            var maxnum = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value <= minvalue) {
                    continue;
                }
                for (j = 0; j < tolen; j++) {
                    var nvalue = value + j;
                    var count = mylist.getCountOfNum(nvalue);
                    if (count < 3) {
                        break;
                    }
                    if (j == tolen - 1) {
                        maxnum = nvalue;
                    }
                }
                if (maxnum != 0) {
                    break;
                }
            }
            if (maxnum == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var value2 = [];
            var getArr;
            for (i = 0; i < tolen; i++) {
                getArr = mylist.getValueByNum(maxnum - i, 3);
                value2 = value2.concat(getArr);
            }
            var cld = this._types.GetType(value2);
            return cld;
        };
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt.prototype.getThree_Double = function (mylist, tolist) {
            var fromlist = mylist.TripleArr;
            var len = fromlist.length;
            if (len < 1) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            if (tolist) {
                minvalue = tolist.TripleArr[0];
            }
            var i = 0;
            var value = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value > minvalue) {
                    break;
                }
                value = 0;
            }
            if (value == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var sign;
            if (mylist.DoubleArr.length > 0) {
                sign = mylist.DoubleArr[0];
            }
            else {
                //没有单牌和对子就不提示了.
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var signArr = mylist.getValueByNum(sign, 2);
            var value2 = mylist.getValueByNum(value, 3);
            var value3 = value2.concat(signArr);
            var cld = this._types.GetType(value3);
            return cld;
        };
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt.prototype.getThree_Signal = function (mylist, tolist) {
            var fromlist = mylist.TripleArr;
            var len = fromlist.length;
            if (len < 1) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            if (tolist) {
                minvalue = tolist.TripleArr[0];
            }
            var i = 0;
            var value = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value > minvalue) {
                    break;
                }
                value = 0;
            }
            if (value == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var sign;
            if (mylist.SingleArr.length > 0) {
                sign = mylist.SingleArr[0];
            }
            else if (mylist.DoubleArr.length > 0) {
                sign = mylist.DoubleArr[0];
            }
            else {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var signArr = mylist.getValueByNum(sign, 1);
            var value2 = mylist.getValueByNum(value, 3);
            var value3 = value2.concat(signArr);
            var cld = this._types.GetType(value3);
            return cld;
        };
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt.prototype.getThree = function (mylist, tolist) {
            var fromlist = mylist.TripleArr;
            var len = fromlist.length;
            if (len < 1) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            if (tolist) {
                minvalue = tolist.TripleArr[0];
            }
            var i = 0;
            var value = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value > minvalue) {
                    break;
                }
                value = 0;
            }
            if (value == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
                ;
            }
            var value2 = mylist.getValueByNum(value, 3);
            var cld = this._types.GetType(value2);
            return cld;
        };
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt.prototype.getDouble = function (mylist, tolist, ismust) {
            var fromlist = mylist.DoubleArr;
            if (ismust) {
                fromlist = mylist.TripleArr;
            }
            var len = fromlist.length;
            if (len < 1) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            if (tolist) {
                minvalue = tolist.DoubleArr[0];
            }
            var i = 0;
            var value = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value > minvalue) {
                    break;
                }
                value = 0;
            }
            if (value == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
                ;
            }
            var value2 = mylist.getValueByNum(value, 2);
            var cld = this._types.GetType(value2);
            return cld;
        };
        //从牌中挑出单张牌
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt.prototype.getSigle = function (mylist, tolist, ismust) {
            var fromlist = mylist.SingleArr;
            if (ismust) {
                fromlist = mylist.AllArr;
            }
            var len = fromlist.length;
            if (len < 1) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            if (tolist) {
                minvalue = tolist.SingleArr[0];
            }
            var i = 0;
            var value = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value > minvalue) {
                    break;
                }
                value = 0;
            }
            if (value == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
                ;
            }
            if ((value == 98 && mylist.getCountOfNum(99) > 0) || (value == 99 && mylist.getCountOfNum(98) > 0)) {
                return this.getBomb(mylist, null);
            }
            var value2 = mylist.getValueByNum(value, 1);
            var cld = this._types.GetType(value2);
            return cld;
        };
        //从大到小出单牌,有王除外.
        Prompt.prototype.getSigleMaxEM = function (mylist) {
            if (mylist.DoubleArr.length > 0 || mylist.TripleArr.length > 0 || mylist.QuadrupleArr.length > 0 || mylist.HasBomb()) {
                return null;
            }
            var fromlist = mylist.SingleArr;
            var len = fromlist.length;
            if (len < 1) {
                return null;
            }
            var minvalue = 0;
            var i = 0;
            var value = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value > minvalue) {
                    minvalue = value;
                }
            }
            if (value == 0) {
                return null;
            }
            if (value > 14) {
                return null;
            }
            var value2 = mylist.getValueByNum(value, 1);
            var cld = this._types.GetType(value2);
            return cld;
        };
        return Prompt;
    }());
    gameLogic.Prompt = Prompt;
    __reflect(Prompt.prototype, "gameLogic.Prompt");
})(gameLogic || (gameLogic = {}));
var gameLogic;
(function (gameLogic) {
    //提示类,不考虑牌型,无脑提示有没有大牌
    var Prompt2 = (function () {
        function Prompt2() {
            this._types = new gameLogic.PlayCardTypes();
            this._types = new gameLogic.PlayCardTypes();
        }
        /**
         * 选择最优牌
         * @param mylist 玩家自己的手牌
         * @param tableList 桌上牌,
         * @param enemycount 敌人的手牌数量
         * @param teamcount 队友的手牌数量
         * @constructor
         */
        Prompt2.prototype.GetPrompt = function (mylist, tableList) {
            return this.getMinListByType(mylist, tableList.Type, tableList);
        };
        Prompt2.prototype.getMinListByType = function (mylist, type, tolist) {
            switch (type) {
                case gameLogic.PlayCardTypes.Types_Signal:
                    return this.getSigle(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_Double:
                    return this.getDouble(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_Three:
                    return this.getThree(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_Three_Signal:
                    return this.getThree_Signal(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_Three_Double:
                    return this.getThree_Double(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_Four_Double:
                    return this.getBomb(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_Four_Signal:
                    return this.getBomb(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_ThreeN:
                    return this.getThreeN(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_ThreeN_Signal:
                    return this.getThreeN_Signal(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_ThreeN_Double:
                    return this.getThreeN_Double(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_List:
                    return this.getList(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_DoubleN:
                    return this.getDoubleN(mylist, tolist);
                case gameLogic.PlayCardTypes.Types_Bomb:
                    return this.getBomb(mylist, tolist);
                default:
                    break;
            }
        };
        /**
         * 获取炸弹
         * @param tolist
         * @returns {any}
         */
        Prompt2.prototype.getBomb = function (mylist, tolist) {
            var fromlist = mylist.QuadrupleArr;
            var bigkingcount = mylist.getCountOfNum(99);
            var tinykingcount = mylist.getCountOfNum(98);
            var len = fromlist.length;
            if (len < 1 && (bigkingcount < 1 || tinykingcount < 1) || (tolist && tolist.AllArr.length == 2)) {
                return null;
            }
            var minvalue = 0;
            if (tolist) {
                minvalue = tolist.QuadrupleArr[0];
            }
            var i = 0;
            var value = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value > minvalue) {
                    break;
                }
                value = 0;
            }
            if (value > 0) {
                var value2 = mylist.getValueByNum(value, 4);
                var cld = this._types.GetType(value2);
                return cld;
            }
            else if (bigkingcount > 0 && tinykingcount > 0) {
                var king1 = mylist.getValueByNum(98, 1);
                var king2 = mylist.getValueByNum(99, 1);
                var kingbomb = king1.concat(king2);
                var cld = this._types.GetType(kingbomb);
                return cld;
            }
            return null;
        };
        /**
         * 获取飞机牌
         * @param tolist
         * @returns {any}
         */
        Prompt2.prototype.getDoubleN = function (mylist, tolist) {
            var fromlist = mylist.DoubleArr;
            var len = fromlist.length;
            if (len < 3) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            var tolen = 0; //顺子长度
            var tomax = 10; //顺子最大长度
            if (tolist) {
                minvalue = tolist.DoubleArr[0];
                tolen = tolist.DoubleArr.length;
            }
            var i = 0;
            var j = 0;
            var value = 0;
            var maxnum = 0;
            var maxlcount = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value <= minvalue) {
                    continue;
                }
                if (tolist) {
                    for (j = 0; j < tolen; j++) {
                        var nvalue = value + j;
                        var count = mylist.getCountOfNum(nvalue);
                        if (count < 2) {
                            break;
                        }
                        if (j == tolen - 1) {
                            maxnum = nvalue;
                        }
                    }
                    if (maxnum != 0) {
                        break;
                    }
                }
                else {
                    for (j = 0; j < tomax; j++) {
                        var nvalue = value + j;
                        var count = mylist.getCountOfNum(nvalue);
                        if (count < 2) {
                            break;
                        }
                        else {
                            tolen++;
                            if (tolen > 2 && tolen > maxlcount) {
                                maxlcount = tolen;
                                maxnum = nvalue;
                            }
                        }
                    }
                    if (i >= len - 1) {
                        tolen = maxlcount;
                    }
                    else {
                        tolen = 0;
                    }
                }
            }
            if (maxnum == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var value2 = [];
            var getArr;
            for (i = 0; i < tolen; i++) {
                getArr = mylist.getValueByNum(maxnum - i, 2);
                value2 = value2.concat(getArr);
            }
            var cld = this._types.GetType(value2);
            return cld;
        };
        Prompt2.prototype.getList = function (mylist, tolist) {
            var fromlist = mylist.OneArr;
            var len = fromlist.length;
            if (len < 5) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            var tolen = 0; //顺子长度
            var tomax = 12; //顺子最大长度
            if (tolist) {
                minvalue = tolist.SingleArr[0];
                tolen = tolist.SingleArr.length;
            }
            var i = 0;
            var j = 0;
            var value = 0;
            var maxnum = 0;
            var maxlcount = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value <= minvalue) {
                    continue;
                }
                if (tolist) {
                    for (j = 0; j < tolen; j++) {
                        var nvalue = value + j;
                        var count = mylist.getCountOfNum(nvalue);
                        if (count < 1) {
                            break;
                        }
                        if (j == tolen - 1) {
                            maxnum = nvalue;
                        }
                    }
                    if (maxnum != 0) {
                        break;
                    }
                }
                else {
                    for (j = 0; j < tomax; j++) {
                        var nvalue = value + j;
                        var count = mylist.getCountOfNum(nvalue);
                        if (count < 1) {
                            break;
                        }
                        else {
                            tolen++;
                            if (tolen > 4 && tolen > maxlcount) {
                                maxlcount = tolen;
                                maxnum = nvalue;
                            }
                        }
                    }
                    if (i >= len - 1) {
                        tolen = maxlcount;
                    }
                    else {
                        tolen = 0;
                    }
                }
            }
            if (maxnum == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var value2 = [];
            var getArr;
            for (i = 0; i < tolen; i++) {
                getArr = mylist.getValueByNum(maxnum - i, 1);
                value2 = value2.concat(getArr);
            }
            var cld = this._types.GetType(value2);
            return cld;
        };
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt2.prototype.getThreeN_Signal = function (mylist, tolist) {
            var fromlist = mylist.TripleArr;
            var len = fromlist.length;
            if (len < 2) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            var tolen = 2; //飞机长度
            if (tolist) {
                minvalue = tolist.TripleArr[0];
                tolen = tolist.TripleArr.length;
            }
            if (len < tolen) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var i = 0;
            var j = 0;
            var value = 0;
            var maxnum = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value <= minvalue) {
                    continue;
                }
                for (j = 0; j < tolen; j++) {
                    var nvalue = value + j;
                    var count = mylist.getCountOfNum(nvalue);
                    if (count < 3) {
                        break;
                    }
                    if (j == tolen - 1) {
                        maxnum = nvalue;
                    }
                }
                if (maxnum != 0) {
                    break;
                }
            }
            if (maxnum == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var value2 = [];
            var getArr;
            for (i = 0; i < tolen; i++) {
                getArr = mylist.getValueByNum(maxnum - i, 3);
                value2 = value2.concat(getArr);
            }
            var singallist = mylist.getSingleValueExceptNum(value2);
            if (singallist.length < tolen) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            else {
                var sslist = singallist.slice(0, tolen);
                value2 = value2.concat(sslist);
            }
            var cld = this._types.GetType(value2);
            return cld;
        };
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt2.prototype.getThreeN_Double = function (mylist, tolist) {
            var fromlist = mylist.TripleArr;
            var len = fromlist.length;
            if (len < 2) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            var tolen = 2; //飞机长度
            if (tolist) {
                minvalue = tolist.TripleArr[0];
                tolen = tolist.TripleArr.length;
            }
            if (len < tolen) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var i = 0;
            var j = 0;
            var value = 0;
            var maxnum = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value <= minvalue) {
                    continue;
                }
                for (j = 0; j < tolen; j++) {
                    var nvalue = value + j;
                    var count = mylist.getCountOfNum(nvalue);
                    if (count < 3) {
                        break;
                    }
                    if (j == tolen - 1) {
                        maxnum = nvalue;
                    }
                }
                if (maxnum != 0) {
                    break;
                }
            }
            if (maxnum == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var value2 = [];
            var getArr;
            for (i = 0; i < tolen; i++) {
                getArr = mylist.getValueByNum(maxnum - i, 3);
                value2 = value2.concat(getArr);
            }
            var singallist = mylist.getDoubleValueExceptNum(value2);
            if (singallist.length < tolen) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            else {
                var sslist = singallist.slice(0, tolen);
                value2 = value2.concat(sslist);
            }
            var cld = this._types.GetType(value2);
            return cld;
        };
        /**
         * 获取飞机牌
         * @param tolist
         * @returns {any}
         */
        Prompt2.prototype.getThreeN = function (mylist, tolist) {
            var fromlist = mylist.TripleArr;
            var len = fromlist.length;
            if (len < 2) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            var tolen = 2; //飞机长度
            if (tolist) {
                minvalue = tolist.TripleArr[0];
                tolen = tolist.TripleArr.length;
            }
            if (len < tolen) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var i = 0;
            var j = 0;
            var value = 0;
            var maxnum = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value <= minvalue) {
                    continue;
                }
                for (j = 0; j < tolen; j++) {
                    var nvalue = value + j;
                    var count = mylist.getCountOfNum(nvalue);
                    if (count < 3) {
                        break;
                    }
                    if (j == tolen - 1) {
                        maxnum = nvalue;
                    }
                }
                if (maxnum != 0) {
                    break;
                }
            }
            if (maxnum == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var value2 = [];
            var getArr;
            for (i = 0; i < tolen; i++) {
                getArr = mylist.getValueByNum(maxnum - i, 3);
                value2 = value2.concat(getArr);
            }
            var cld = this._types.GetType(value2);
            return cld;
        };
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt2.prototype.getThree_Double = function (mylist, tolist) {
            var temp = mylist.OneArr;
            var fromlist = [];
            for (var i = 0; i < temp.length; i++) {
                if (mylist.getCountOfNum(temp[i]) > 2) {
                    fromlist.push(temp[i]);
                }
            }
            var len = fromlist.length;
            if (len < 1) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            if (tolist) {
                minvalue = tolist.TripleArr[0];
            }
            var i = 0;
            var value = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value > minvalue) {
                    break;
                }
                value = 0;
            }
            if (value == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var value2 = mylist.getValueByNum(value, 3);
            var singallist = mylist.getDoubleValueExceptNum(value2);
            if (singallist.length < 1) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            else {
                var sslist = singallist.slice(0, 1);
                value2 = value2.concat(sslist);
            }
            var cld = this._types.GetType(value2);
            return cld;
        };
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt2.prototype.getThree_Signal = function (mylist, tolist) {
            var temp = mylist.OneArr;
            var fromlist = [];
            for (var i = 0; i < temp.length; i++) {
                if (mylist.getCountOfNum(temp[i]) > 2) {
                    fromlist.push(temp[i]);
                }
            }
            var len = fromlist.length;
            if (len < 1) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            if (tolist) {
                minvalue = tolist.TripleArr[0];
            }
            var i = 0;
            var value = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value > minvalue) {
                    break;
                }
                value = 0;
            }
            if (value == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var value2 = mylist.getValueByNum(value, 3);
            var singallist = mylist.getSingleValueExceptNum(value2);
            if (singallist.length < 1) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            else {
                var sslist = singallist.slice(0, 1);
                value2 = value2.concat(sslist);
            }
            var cld = this._types.GetType(value2);
            return cld;
        };
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt2.prototype.getThree = function (mylist, tolist) {
            var temp = mylist.OneArr;
            var fromlist = [];
            for (var i = 0; i < temp.length; i++) {
                if (mylist.getCountOfNum(temp[i]) > 2) {
                    fromlist.push(temp[i]);
                }
            }
            var len = fromlist.length;
            if (len < 1) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            if (tolist) {
                minvalue = tolist.TripleArr[0];
            }
            var i = 0;
            var value = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value > minvalue) {
                    break;
                }
                value = 0;
            }
            if (value == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
                ;
            }
            var value2 = mylist.getValueByNum(value, 3);
            var cld = this._types.GetType(value2);
            return cld;
        };
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt2.prototype.getDouble = function (mylist, tolist, ismust) {
            var temp = mylist.OneArr;
            var fromlist = [];
            for (var i = 0; i < temp.length; i++) {
                if (mylist.getCountOfNum(temp[i]) > 1) {
                    fromlist.push(temp[i]);
                }
            }
            var len = fromlist.length;
            if (len < 1) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            if (tolist) {
                minvalue = tolist.DoubleArr[0];
            }
            var i = 0;
            var value = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value > minvalue) {
                    break;
                }
                value = 0;
            }
            if (value == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
                ;
            }
            var value2 = mylist.getValueByNum(value, 2);
            var cld = this._types.GetType(value2);
            return cld;
        };
        //从牌中挑出单张牌
        /**
         *
         * @param tolist 要比tolist的牌大
         * @returns {any}
         */
        Prompt2.prototype.getSigle = function (mylist, tolist, ismust) {
            var fromlist = mylist.OneArr;
            var len = fromlist.length;
            if (len < 1) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
            }
            var minvalue = 0;
            if (tolist) {
                minvalue = tolist.SingleArr[0];
            }
            var i = 0;
            var value = 0;
            for (i = 0; i < len; i++) {
                value = fromlist[i];
                if (value > minvalue) {
                    break;
                }
                value = 0;
            }
            if (value == 0) {
                if (tolist != null) {
                    return this.getBomb(mylist);
                }
                else {
                    return null;
                }
                ;
            }
            var value2 = mylist.getValueByNum(value, 1);
            var cld = this._types.GetType(value2);
            return cld;
        };
        return Prompt2;
    }());
    gameLogic.Prompt2 = Prompt2;
    __reflect(Prompt2.prototype, "gameLogic.Prompt2");
})(gameLogic || (gameLogic = {}));
var gameLogic;
(function (gameLogic) {
    //发牌逻辑
    var SendCard = (function () {
        function SendCard() {
        }
        //获取初始卡片,四张四张发.容易做规则,客户要求0.5的概率出炸弹
        //返回四个数组,0,1,2为玩家牌,3为地主牌三张
        SendCard.prototype.GetCardRandom = function () {
            var list = null;
            var list1 = [];
            var list2 = [];
            var list3 = [];
            var bomblist = [];
            var i = 0;
            list = SendCard.CardList.concat();
            if (Math.random() > 0.5) {
                bomblist = this.doBombArr(list);
                console.info("SendCard-GetCardRandom> 有炸弹");
            }
            ArrayTools.RandomSort(list);
            var bombranid = Math.floor(Math.random() * 3);
            this.addplaylist(list, bomblist, list1, 0 == bombranid);
            this.addplaylist(list, bomblist, list2, 1 == bombranid);
            this.addplaylist(list, bomblist, list3, 2 == bombranid);
            return [list1, list2, list3, list];
        };
        //分配玩家手牌,随机获得炸弹牌
        SendCard.prototype.addplaylist = function (list, bomblist, plist, hasbomb) {
            if (hasbomb && bomblist.length > 0) {
                while (bomblist.length > 0) {
                    plist.push(bomblist.pop());
                }
            }
            while (plist.length < 17) {
                plist.push(list.pop());
            }
            ArrayTools.RandomSort(plist);
        };
        //从原牌中删除炸弹牌,并且返回炸弹拍数组
        SendCard.prototype.doBombArr = function (list) {
            var blist = this.getBombArr();
            var i = 0;
            var len = list.length;
            var j = 0;
            var jlen = blist.length;
            var insertid = 4 * Math.floor(Math.random() * (52 - 4) / 3);
            //原牌中去掉炸弹
            for (i = len - 1; i >= 0; i--) {
                for (j = 0; j < jlen; j++) {
                    if (list[i] == blist[j]) {
                        list.splice(i, 1);
                        break;
                    }
                }
            }
            return blist;
        };
        SendCard.prototype.getBombArr = function () {
            var len = SendCard.ValueList.length;
            var ranid = Math.floor(Math.random() * len);
            var id = SendCard.ValueList[ranid];
            var list = [100 + id, 200 + id, 300 + id, 400 + id];
            return list;
        };
        //扑克牌数字 3,4,5,6,7,8,9,10,11,12,13,14=1,20=2,98=小王,99=大王
        //花色 黑红梅方:100,200,300,400
        //扑克牌=花色+扑克牌数字
        SendCard.CardList = [
            103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 120,
            203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 220,
            303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 320,
            403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 420,
            998, 999
        ];
        //不带花色纯数字
        SendCard.ValueList = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20];
        return SendCard;
    }());
    gameLogic.SendCard = SendCard;
    __reflect(SendCard.prototype, "gameLogic.SendCard");
})(gameLogic || (gameLogic = {}));
var Config = (function () {
    function Config() {
    }
    Config.IsHide = false;
    Config.System = "Windows"; //Android,iPhone,Windows Phone, Windows
    Config.StageWidth = 640;
    Config.StageHeight = 1136;
    Config.MinStageHeight = 585;
    Config.MinStageY = 1;
    Config.IsBgTouch = false;
    return Config;
}());
__reflect(Config.prototype, "Config");
var network;
(function (network) {
    /**
     * 发送或接收网络对战消息处理
     */
    var BattleMsg = (function (_super) {
        __extends(BattleMsg, _super);
        function BattleMsg() {
            var _this = _super.call(this) || this;
            _this.battleEventMap = [];
            _this.AddEventMap();
            return _this;
        }
        /**
         * 获取网络消息管理实例
         */
        BattleMsg.getInstance = function () {
            if (BattleMsg._instance == null) {
                BattleMsg._instance = new BattleMsg();
            }
            return BattleMsg._instance;
        };
        BattleMsg.prototype.AddEventMap = function () {
            this.battleEventMap[network.NetMsgEvent.GAME_READY_R] = network.BattleMsgEvent.GAME_READY;
            this.battleEventMap[network.NetMsgEvent.CALL_LAND_RO] = network.BattleMsgEvent.CALL_LANDLORD_OVER;
            this.battleEventMap[network.NetMsgEvent.CALL_LAND_RN] = network.BattleMsgEvent.CALL_LANDLORD_NEXT;
            this.battleEventMap[network.NetMsgEvent.PLAY_CARDS_R] = network.BattleMsgEvent.PLAYER_CARDS;
            this.battleEventMap[network.NetMsgEvent.GAME_OVER_R] = network.BattleMsgEvent.GAME_OVER;
            this.battleEventMap[network.NetMsgEvent.REPROT_SCORE_R] = network.BattleMsgEvent.REPORT_DATA;
            this.battleEventMap[network.NetMsgEvent.GAME_IS_OKR] = network.BattleMsgEvent.GAME_IS_OK;
        };
        /**
         * 接收消息
         * @param {any} msg
         */
        BattleMsg.prototype.ReceiveMessage = function (msg) {
            console.info("ReceiveMessage:", msg);
            /**
             * 消息解析
             */
            var event = JSON.parse(msg);
            if (!event.hasOwnProperty("action") || !event.hasOwnProperty("data")) {
                return -1;
            }
            var obj = this.ResolverMsg(Number(event.action), event.data);
            // console.info("event.action",msg);
            console.info("ReceiveMessage:", this.battleEventMap[event.action], obj);
            this.dispatchEvent(new egret.Event(this.battleEventMap[event.action], false, false, obj));
            //触发监听事件
            return 0;
        };
        /**
         * 消息解析
         */
        BattleMsg.prototype.ResolverMsg = function (action, data) {
            var pk = new network.DefaultResolver();
            // switch(action){
            // 	case NetMsgEvent.GAME_READY_R:
            // 	pk = new GameReadyResolver();
            // 	break;
            // 	case NetMsgEvent.RESET_ROOM_R:
            // 	break;
            // 	case NetMsgEvent.REPROT_SCORE_R:
            // 	break;
            // 	default:
            // 	console.warn("invaild message action!",action,data);
            // 	break;
            // }
            if (pk == null) {
                return "";
            }
            return pk.getParse(data);
        };
        //发送消息
        BattleMsg.prototype.sendMessage = function (ev, data) {
            console.info("sendMessage action:", ev, data);
            var pk = new network.DefaultResolver();
            switch (ev) {
                case network.NetMsgEvent.CALL_LAND_S:
                    pk = new network.CallLandLordResolver();
                    break;
                case network.NetMsgEvent.GAME_READY_S:
                    pk = new network.GameReadyResolver();
                    break;
                case network.NetMsgEvent.RESET_ROOM_S:
                    break;
                case network.NetMsgEvent.REPROT_SCORE_S:
                    break;
                case network.NetMsgEvent.PLAY_CARDS_S:
                    pk = new network.PlayCardsResolver();
                    break;
                case network.NetMsgEvent.GAME_OVER_S:
                    pk = new network.GameOverResolver();
                    break;
                default:
                    break;
            }
            if (pk == null) {
                return "";
            }
            var tmpdata = pk.toPackage(ev, data);
            //console.info("tmpdata:",tmpdata);
            return tmpdata;
        };
        //发送给gameServer
        BattleMsg.prototype.sendToGameServer = function (action, data) {
            //this.ReceiveMessage(this.sendMessage(action, data));
            MatchvsData.MatchvsRep.gameServerNotify = this.gameServerNotify.bind(this);
            console.info("sendToGameServer");
            MatchvsData.MatchvsReq.sendEventEx(1, this.sendMessage(action, data), 0, []);
        };
        //发送给玩家
        BattleMsg.prototype.sendToPlayers = function (action, data) {
            this.ReceiveMessage(this.sendMessage(action, data));
            // MatchvsData.MatchvsRep.sendEventNotify = function(eventInfo:MsSendEventNotify){
            // 	console.info("sendEventNotify");
            // 	this.ReceiveMessage(eventInfo.cpProto);
            // }.bind(this);
            // MatchvsData.MatchvsRep.sendEventResponse = function(rsp:MsSendEventRsp){
            // 	console.info("sendEventNotify");
            // 	this.ReceiveMessage(rsp);
            // }.bind(this);
            //MatchvsData.MatchvsReq.sendEvent(this.sendMessage(action, data));
        };
        BattleMsg.prototype.gameServerNotify = function (eventInfo) {
            console.info("gameServerNotify");
            this.ReceiveMessage(eventInfo.cpProto);
        };
        BattleMsg._instance = null;
        return BattleMsg;
    }(egret.EventDispatcher));
    network.BattleMsg = BattleMsg;
    __reflect(BattleMsg.prototype, "network.BattleMsg");
})(network || (network = {}));
var network;
(function (network) {
    var NetworkStateCheck = (function () {
        function NetworkStateCheck() {
            //错误码选择
            this._errCodeMap = [];
            this._curr = null;
            this._gtwDisConn = false;
            this.InitErrorData();
        }
        NetworkStateCheck.prototype.InitErrorData = function () {
            this.addErrCodeData(1001, "您的【游戏】连接断开, 需要重新登录...", this.returnSceneLogin);
            this.addErrCodeData(1002, "您的【房间】连接断开, 请重开游戏...", this.returnSceneGameLoy);
            this.addErrCodeData(406, "房间已经关闭...", this.returnSceneGameLoy);
            this.addErrCodeData(405, "房间人已经满了...", this.returnSceneGameLoy);
            this.addErrCodeData(404, "找不到您要的信息...", this.returnSceneLogin);
            this.addErrCodeData(500, "游戏服务器错误...", this.returnSceneLogin);
            this.addErrCodeData(402, "用户信息验证错误...", this.returnSceneLogin);
        };
        NetworkStateCheck.prototype.addErrCodeData = function (code, msg, call) {
            this._errCodeMap[code] = { message: msg, callBack: call };
        };
        NetworkStateCheck.getInstance = function () {
            if (NetworkStateCheck._instance == null) {
                NetworkStateCheck._instance = new NetworkStateCheck();
            }
            return NetworkStateCheck._instance;
        };
        NetworkStateCheck.Release = function () {
            if (NetworkStateCheck._instance) {
                NetworkStateCheck._instance = null;
            }
        };
        /**
         * 取消监听
         */
        NetworkStateCheck.prototype.CancelListen = function () {
            PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_NETWORKSTATE, this.networkStateNotify, this);
            PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_ERROR, this.NetorkError, this);
            if (this._curr && "Release" in this._curr) {
                this._curr.Release();
            }
            console.log("CancelListen:取消网络错误监听");
        };
        /**
         * 注册网络监听
         */
        NetworkStateCheck.prototype.RegistNetListen = function (obj) {
            PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_NETWORKSTATE, this.networkStateNotify, this);
            PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_ERROR, this.NetorkError, this);
            this._curr = obj;
        };
        /**
         * 房间用户状态变化回调
         */
        NetworkStateCheck.prototype.networkStateNotify = function (e) {
            var data = e.data;
            if (data.state == 3) {
                this.CancelListen();
                SceneManager.ErrorPage("其他玩家网络连接断开，请返回到大厅...", this.returnSceneGameLoy, this);
            }
        };
        /**
         * 跳到大厅
         */
        NetworkStateCheck.prototype.returnSceneGameLoy = function () {
            PokeMatchvsEngine.getInstance.leaveRoom("玩家断开");
            console.info("跳到大厅");
            this._gtwDisConn = false;
            SceneManager.showScene(Game);
        };
        /**
         * 跳到登录
         */
        NetworkStateCheck.prototype.returnSceneLogin = function () {
            console.info("跳到登录");
            this._gtwDisConn = false;
            PokeMatchvsEngine.getInstance.init(MatchvsData.pChannel, MatchvsData.pPlatform, MatchvsData.gameID);
            SceneManager.showScene(Login);
        };
        /**
         * 网络错误回调
         */
        NetworkStateCheck.prototype.NetorkError = function (e) {
            var data = e.data;
            console.info("触发错误：", data.code);
            if (data.code == 1001) {
                this._gtwDisConn = true;
            }
            if (data.code == 1002 && this._gtwDisConn) {
                data.code = 1001;
            }
            var errData = this._errCodeMap[Number(data.code)];
            if (errData) {
                this.CancelListen();
                SceneManager.ErrorPage(errData.message, errData.callBack, this);
            }
            // }else{
            // 	SceneManager.ErrorPage("服务返回错误："+data.code,this.returnSceneLogin,this);
            // }
        };
        NetworkStateCheck._instance = null;
        return NetworkStateCheck;
    }());
    network.NetworkStateCheck = NetworkStateCheck;
    __reflect(NetworkStateCheck.prototype, "network.NetworkStateCheck");
})(network || (network = {}));
var network;
(function (network) {
    var CallLandLordResolver = (function (_super) {
        __extends(CallLandLordResolver, _super);
        function CallLandLordResolver() {
            return _super.call(this) || this;
        }
        /**
         * 发送消息封包
         */
        CallLandLordResolver.prototype.Package = function (data) {
            var event = {
                action: 126,
                status: 0,
                data: {
                    landOwner: 85642,
                    landCards: [309, 407, 410],
                    value: 3
                }
            };
            event = data;
            console.log("Package", event);
            return event;
        };
        /**
         * 接收消息解包
         */
        CallLandLordResolver.prototype.Parse = function (data) {
            return data;
        };
        return CallLandLordResolver;
    }(network.IResolver));
    network.CallLandLordResolver = CallLandLordResolver;
    __reflect(CallLandLordResolver.prototype, "network.CallLandLordResolver");
})(network || (network = {}));
var network;
(function (network) {
    var DefaultResolver = (function (_super) {
        __extends(DefaultResolver, _super);
        function DefaultResolver() {
            return _super.call(this) || this;
        }
        DefaultResolver.prototype.Package = function (data) {
            return data;
        };
        DefaultResolver.prototype.Parse = function (data) {
            return data;
        };
        return DefaultResolver;
    }(network.IResolver));
    network.DefaultResolver = DefaultResolver;
    __reflect(DefaultResolver.prototype, "network.DefaultResolver");
})(network || (network = {}));
var network;
(function (network) {
    var GameOverResolver = (function (_super) {
        __extends(GameOverResolver, _super);
        function GameOverResolver() {
            return _super.call(this) || this;
        }
        /**
         * 发送消息封包
         */
        GameOverResolver.prototype.Package = function (data) {
            var event = {
                action: 133,
                data: data
            };
            event = data;
            return event;
        };
        /**
         * 接收消息解包
         */
        GameOverResolver.prototype.Parse = function (data) {
            return data;
        };
        return GameOverResolver;
    }(network.IResolver));
    network.GameOverResolver = GameOverResolver;
    __reflect(GameOverResolver.prototype, "network.GameOverResolver");
})(network || (network = {}));
var network;
(function (network) {
    var GameReadyResolver = (function (_super) {
        __extends(GameReadyResolver, _super);
        function GameReadyResolver() {
            return _super.call(this) || this;
        }
        /**
         * 发送消息封包
         */
        GameReadyResolver.prototype.Package = function (data) {
            var event = {
                action: 121,
                data: {
                    userCards: [
                        {
                            userID: 96648,
                            card: [210, 420, 214, 403, 103, 310, 304, 106, 303, 212, 205, 414, 203, 109, 999, 998, 307]
                        },
                        {
                            userID: 85642,
                            card: [411, 306, 120, 311, 105, 207, 206, 112, 412, 208, 114, 313, 213, 409, 314, 320, 404]
                        },
                        {
                            userID: 75646,
                            card: [408, 308, 406, 204, 113, 305, 107, 211, 110, 413, 220, 312, 104, 111, 405, 209, 108]
                        }
                    ],
                    lanownList: [309, 407, 410],
                    callOwner: 85642,
                }
            };
            event = data;
            //console.log("Package",event);
            return event;
        };
        /**
         * 接收消息解包
         */
        GameReadyResolver.prototype.Parse = function (data) {
            return data;
        };
        return GameReadyResolver;
    }(network.IResolver));
    network.GameReadyResolver = GameReadyResolver;
    __reflect(GameReadyResolver.prototype, "network.GameReadyResolver");
})(network || (network = {}));
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-present, Egret Technology.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var LoadingUI = (function (_super) {
    __extends(LoadingUI, _super);
    function LoadingUI() {
        var _this = _super.call(this) || this;
        _this.createView();
        return _this;
    }
    LoadingUI.prototype.createView = function () {
        this.textField = new egret.TextField();
        this.addChild(this.textField);
        this.textField.y = 300;
        this.textField.width = 480;
        this.textField.height = 100;
        this.textField.textAlign = "center";
    };
    LoadingUI.prototype.onProgress = function (current, total) {
        this.textField.text = "Loading..." + current + "/" + total;
    };
    return LoadingUI;
}(egret.Sprite));
__reflect(LoadingUI.prototype, "LoadingUI", ["RES.PromiseTaskReporter"]);
var network;
(function (network) {
    var PlayCardsResolver = (function (_super) {
        __extends(PlayCardsResolver, _super);
        function PlayCardsResolver() {
            return _super.call(this) || this;
        }
        /**
         * 发送消息封包
         */
        PlayCardsResolver.prototype.Package = function (data) {
            var event = {
                action: 131,
                data: data
            };
            event = data;
            return event;
        };
        /**
         * 接收消息解包
         */
        PlayCardsResolver.prototype.Parse = function (data) {
            return data;
        };
        return PlayCardsResolver;
    }(network.IResolver));
    network.PlayCardsResolver = PlayCardsResolver;
    __reflect(PlayCardsResolver.prototype, "network.PlayCardsResolver");
})(network || (network = {}));
/**
 * Matchvs常量定义
 */
var MatchvsData = (function () {
    function MatchvsData() {
    }
    MatchvsData.getDefaultUserProfile = function () {
        var obj = { nickName: GlobalData.myUser.nickName, avator: GlobalData.myUser.avator, pointValue: GlobalData.myUser.pointValue,
            userID: GlobalData.myUser.userID };
        egret.log("自己加入房间的USerProFile", GlobalData.myUser.nickName + "/" + GlobalData.myUser.avator + "/" + GlobalData.myUser.pointValue + "/" +
            GlobalData.myUser.userID);
        return JSON.stringify(obj);
    };
    MatchvsData.gameID = 200787;
    MatchvsData.appKey = "de7c4a439d2948d880451c25c910b239";
    MatchvsData.secret = "5667067032b644c687c0a86ca9faa2d6";
    MatchvsData.gameVision = 1.0;
    MatchvsData.DeviceID = "0";
    MatchvsData.gatewayID = 1;
    MatchvsData.pChannel = "MatchVS";
    MatchvsData.pPlatform = "alpha";
    MatchvsData.HtttpUrl = "https://vsopen.matchvs.com/wc5/getGameData.do?";
    MatchvsData.alphaHttpUrl = (MatchvsData.pPlatform == "release" ? "https://vsopen.matchvs.com/wc5/getGameData.do?" : "https://alphavsopen.matchvs.com/wc5/getGameData.do?");
    MatchvsData.MatchvsReq = new MatchvsEngine();
    MatchvsData.MatchvsRep = new MatchvsResponse();
    MatchvsData.maxPlayer = 3; //随机匹配房间最大人数
    MatchvsData.defaultIcon = ["http://193.112.47.13/headimg/1.jpg",
        "http://193.112.47.13/headimg/2.jpg",
        "http://193.112.47.13/headimg/3.jpg",
        "http://193.112.47.13/headimg/4.jpg",
        "http://193.112.47.13/headimg/5.jpg",
        "http://193.112.47.13/headimg/6.jpg",
        "http://193.112.47.13/headimg/7.jpg",
        "http://193.112.47.13/headimg/8.jpg",
        "http://193.112.47.13/headimg/9.jpg",
        "http://193.112.47.13/headimg/11.jpg",
        "http://193.112.47.13/headimg/12.jpg",
        "http://193.112.47.13/headimg/13.jpg",
        "http://193.112.47.13/headimg/14.jpg",
    ];
    MatchvsData.FCdefaultIcon = ["https://scontent-lax3-1.xx.fbcdn.net/v/t1.0-0/p206x206/22366452_1967021146906417_8277070881351653528_n.jpg?_nc_cat=0&oh=b3dfcda6a2aba65b074a779c8985c519&oe=5B8BDAE3",
        "https://scontent-lax3-1.xx.fbcdn.net/v/t1.0-0/p206x206/22366452_1967021146906417_8277070881351653528_n.jpg?_nc_cat=0&oh=b3dfcda6a2aba65b074a779c8985c519&oe=5B8BDAE3",
        "https://scontent-lax3-1.xx.fbcdn.net/v/t1.0-0/p206x206/22366452_1967021146906417_8277070881351653528_n.jpg?_nc_cat=0&oh=b3dfcda6a2aba65b074a779c8985c519&oe=5B8BDAE3",
        "https://scontent-lax3-1.xx.fbcdn.net/v/t1.0-0/p206x206/22366452_1967021146906417_8277070881351653528_n.jpg?_nc_cat=0&oh=b3dfcda6a2aba65b074a779c8985c519&oe=5B8BDAE3",
        "https://scontent-lax3-1.xx.fbcdn.net/v/t1.0-0/p206x206/22366452_1967021146906417_8277070881351653528_n.jpg?_nc_cat=0&oh=b3dfcda6a2aba65b074a779c8985c519&oe=5B8BDAE3",
        "https://scontent-lax3-1.xx.fbcdn.net/v/t1.0-0/p206x206/22366452_1967021146906417_8277070881351653528_n.jpg?_nc_cat=0&oh=b3dfcda6a2aba65b074a779c8985c519&oe=5B8BDAE3",
        "https://scontent-lax3-1.xx.fbcdn.net/v/t1.0-0/p206x206/22366452_1967021146906417_8277070881351653528_n.jpg?_nc_cat=0&oh=b3dfcda6a2aba65b074a779c8985c519&oe=5B8BDAE3",
        "https://scontent-lax3-1.xx.fbcdn.net/v/t1.0-0/p206x206/22366452_1967021146906417_8277070881351653528_n.jpg?_nc_cat=0&oh=b3dfcda6a2aba65b074a779c8985c519&oe=5B8BDAE3",
        "https://scontent-lax3-1.xx.fbcdn.net/v/t1.0-0/p206x206/22366452_1967021146906417_8277070881351653528_n.jpg?_nc_cat=0&oh=b3dfcda6a2aba65b074a779c8985c519&oe=5B8BDAE3",
        "https://scontent-lax3-1.xx.fbcdn.net/v/t1.0-0/p206x206/22366452_1967021146906417_8277070881351653528_n.jpg?_nc_cat=0&oh=b3dfcda6a2aba65b074a779c8985c519&oe=5B8BDAE3",
    ];
    MatchvsData.defaultScore = 10000;
    MatchvsData.defaultRoomInfo = new MsCreateRoomInfo("", 3, 1, 1, 1, "");
    MatchvsData.gameMode = false; // false  代表直接开始游戏，true代表邀请好友开始游戏
    MatchvsData.loginStatus = false;
    return MatchvsData;
}());
__reflect(MatchvsData.prototype, "MatchvsData");
var MatchvsMessage = (function () {
    function MatchvsMessage() {
    }
    /**
     * 定义了Matchvs非对战消息网络事件
     */
    MatchvsMessage.MATCHVS_INIT = "MATCHVS_INIT";
    MatchvsMessage.MATCHVS_REGISTERUSER = "MATCHVS_REGISTERUSER";
    MatchvsMessage.MATCHVS_LOGIN = "MATCHVS_LOGIN";
    MatchvsMessage.MATCHVS_JOINROOM_RSP = "MATCHVS_JOINROOM_RSP";
    MatchvsMessage.MATCHVS_JOINROOM_NOTIFY = "MATCHVS_JOINROOM_NOTIFY";
    MatchvsMessage.MATCHVS_CREATE_ROOM = "MATCHVS_CREATE_ROOM";
    MatchvsMessage.MATCHVS_LEVAE_ROOM_NOTIFY = "MATCHVS_LEVAE_ROOM_NOTIFY";
    MatchvsMessage.MATCHVS_LEVAE_ROOM = "MATCHVS_LEVAE_ROOM";
    MatchvsMessage.MATCHVS_KICK_PLAYER = "MATCHVS_KICK_PLAYER";
    MatchvsMessage.MATCHVS_KICK_PLAYER_NOTIFY = "MATCHVS_KICK_PLAYER_NOTIFY";
    MatchvsMessage.MATCHVS_ROOM_DETAIL_RSP = "MATCHVS_ROOM_DETAIL_RSP";
    MatchvsMessage.MATCHVS_RANK_LIST = "MATCHVS_RANK_LIST";
    MatchvsMessage.MATCHVS_DELET_TIME = "MATCHVS_DELET_TIME";
    MatchvsMessage.MATCHVS_ERROR = "MATCHVS_ERROR";
    MatchvsMessage.MATCHVS_NETWORKSTATE = "MATCHVS_NETWORKSTATE";
    MatchvsMessage.MATCHVS_SEND_EVENT_RSP = "MATCHVS_SEND_EVENT_RSP";
    MatchvsMessage.MATCHVS_SEND_EVENT_NOTIFY = "MATCHVS_SEND_EVENT_NOTIFY";
    return MatchvsMessage;
}());
__reflect(MatchvsMessage.prototype, "MatchvsMessage");
var PokeMatchvsEngine = (function () {
    function PokeMatchvsEngine() {
    }
    Object.defineProperty(PokeMatchvsEngine, "getInstance", {
        get: function () {
            if (this._instance == null) {
                this._instance = new PokeMatchvsEngine();
            }
            return this._instance;
        },
        enumerable: true,
        configurable: true
    });
    /**
     * 初始化
     */
    PokeMatchvsEngine.prototype.init = function (pChannel, pPlatform, gameID) {
        var result = MatchvsData.MatchvsReq.init(MatchvsData.MatchvsRep, pChannel, pPlatform, gameID);
        egret.log("初始化result：" + result);
        return result;
    };
    /**
     * 注册
     */
    PokeMatchvsEngine.prototype.registerUser = function () {
        var result = MatchvsData.MatchvsReq.registerUser();
        egret.log("注册result：" + result);
        return result;
    };
    /**
     * 登录
     */
    PokeMatchvsEngine.prototype.login = function (pUserID, pToken) {
        var result = MatchvsData.MatchvsReq.login(pUserID, pToken, MatchvsData.gameID, MatchvsData.gameVision, MatchvsData.appKey, MatchvsData.secret, MatchvsData.DeviceID, MatchvsData.gatewayID);
        egret.log("登录result：" + result);
        return result;
    };
    /**
     * 快速匹配
     */
    PokeMatchvsEngine.prototype.joinRandomRoom = function (cpProto) {
        var result = MatchvsData.MatchvsReq.joinRandomRoom(MatchvsData.maxPlayer, cpProto);
        egret.log("快速匹配result :" + result);
        return result;
    };
    /**
     * 离开房间
     */
    PokeMatchvsEngine.prototype.leaveRoom = function (cpProto) {
        var result = MatchvsData.MatchvsReq.leaveRoom(cpProto);
        egret.log("离开房间result :" + result);
        return result;
    };
    PokeMatchvsEngine.prototype.loginOut = function () {
        var result = MatchvsData.MatchvsReq.logout("累了困了");
        egret.log("登出：", result);
        return result;
    };
    /**
     * 创建房间
     * @param roomPropety 传递自己的微信昵称与微信头像地址
     */
    PokeMatchvsEngine.prototype.creatRoom = function (roomName, roomPropety, maxPlayer, userProfile) {
        var defaultRoomInfo = new MsCreateRoomInfo(roomName, 3, maxPlayer, 1, 1, roomPropety);
        var result = MatchvsData.MatchvsReq.createRoom(defaultRoomInfo, userProfile);
        egret.log("创建房间result:" + result);
        return result;
    };
    /**
     * 踢人
     */
    PokeMatchvsEngine.prototype.kickPlayer = function (userID, name) {
        var obj = { nickName: name, proto: "你无法跟我一起游戏了" };
        var result = MatchvsData.MatchvsReq.kickPlayer(userID, JSON.stringify(obj));
        egret.log("踢出" + userID + "result:" + result);
        return result;
    };
    /**
     * 加入房间
     * @param userProfile 传递自己的微信昵称与微信头像地址
     */
    PokeMatchvsEngine.prototype.joinRoom = function (roomID, userProfile) {
        var result = MatchvsData.MatchvsReq.joinRoom(roomID, userProfile);
        egret.log("加入房间result:" + result);
        return result;
    };
    /**
     * 获取房间详情
     */
    PokeMatchvsEngine.prototype.getRoomDetail = function (roomID) {
        var result = MatchvsData.MatchvsReq.getRoomDetail(roomID);
        egret.log("获取房间详情result:" + result);
        return result;
    };
    /**
     * 存储数据
     */
    PokeMatchvsEngine.prototype.hashSet = function (key, value) {
        MatchvsData.MatchvsReq.hashSet(MatchvsData.gameID, GlobalData.myUser.userID, key, value);
    };
    /**
     * 获取数据
     */
    PokeMatchvsEngine.prototype.hashGet = function (key) {
        MatchvsData.MatchvsReq.hashGet(MatchvsData.gameID, GlobalData.myUser.userID, key);
    };
    /**
     * 取全局排行榜数据
     */
    PokeMatchvsEngine.prototype.getRankList = function (key) {
        //参数组合是安装首字母排序的
        var keyList = JSON.stringify([{ "key": "rankList" }]);
        egret.log(keyList);
        var params = "gameID=" + MatchvsData.gameID + "&userID=" + GlobalData.myUser.userID + "&keyList=" + keyList;
        //加上 appkey 和 token 进行MD5签名
        var matchvsMD5 = new MD5();
        var sign = matchvsMD5.hex_md5(MatchvsData.appKey + "&gameID=" + MatchvsData.gameID + "&userID=" + GlobalData.myUser.userID + "&" + MatchvsData.secret);
        var rankListUrl = MatchvsData.alphaHttpUrl + params + "&sign=" + sign;
        egret.log(rankListUrl, rankListUrl);
        var http = new MatchvsHttp(PokeMatchvsRep.getInstance);
        http.get(rankListUrl + "&timer=" + key);
    };
    /**
     * 发送消息扩展接口，给gameServer
     */
    PokeMatchvsEngine.prototype.sendEventEx = function (action, cpProto) {
        var result = MatchvsData.MatchvsReq.sendEventEx(1, JSON.stringify({ action: action, data: cpProto }), 1, []);
        console.log("发送消息 result" + result);
        return result;
    };
    return PokeMatchvsEngine;
}());
__reflect(PokeMatchvsEngine.prototype, "PokeMatchvsEngine");
var onGetProgress = (function () {
    function onGetProgress() {
        this.onMsg = function (buf) {
        };
        this.onErr = function (errCode, errMsg) {
        };
    }
    return onGetProgress;
}());
__reflect(onGetProgress.prototype, "onGetProgress");
var PokeMatchvsRep = (function (_super) {
    __extends(PokeMatchvsRep, _super);
    function PokeMatchvsRep() {
        var _this = _super.call(this) || this;
        /**
         * 引擎初始化回调
         */
        _this.initRsp = function (status) {
            if (status === 200) {
                egret.log("初始化成功" + status);
                PokeMatchvsEngine.getInstance.registerUser();
                // this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_INIT,false,false,status));
            }
            else {
                egret.log("初始化失败，错误码" + status);
            }
        };
        /**
         * 注册
         */
        _this.registerUserRsp = function (userInfo) {
            if (userInfo.status == 0) {
                egret.log("注册成功" + userInfo.status);
                PokeMatchvsEngine.getInstance.login(userInfo.id, userInfo.token);
                this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_REGISTERUSER, false, false, userInfo));
            }
            else {
                egret.log("注册失败，错误码：" + userInfo.status);
            }
        };
        /**
         * 登录
         */
        _this.loginRsp = function (loginRsp) {
            // if(loginRsp.status == 200) {
            egret.log("登录:" + loginRsp.status);
            // 没有断线重连功能，登陆成功后发现还再房间中就退出房间
            if (loginRsp.roomID != undefined && loginRsp.roomID != "") {
                PokeMatchvsEngine.getInstance.leaveRoom(MatchvsData.getDefaultUserProfile());
            }
            this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_LOGIN, false, false, loginRsp));
            // } else {
            // egret.log("登录失败，错误码："+loginRsp.status);
            // }
        };
        /**
         * 进入房间的回调
         */
        _this.joinRsp = function (status, roomUserInfonList, roomInfo) {
            if (status == 200) {
                egret.log("进入房间成功" + status);
                roomUserInfonList.roomID = roomInfo.roomID;
                roomUserInfonList.ownerId = roomInfo.ownerId;
                this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_JOINROOM_RSP, false, false, roomUserInfonList));
            }
            else {
                egret.log("进入房间失败，错误码：" + status);
                Toast.show("进入房间失败");
            }
        };
        /**
         * 其他玩家进入房间回调
         */
        _this.joinRoomNotify = function (roomUserInfon) {
            egret.log(roomUserInfon.userId + "进入了房间");
            this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_JOINROOM_NOTIFY, false, false, roomUserInfon));
        };
        /**
         * 其他玩家离开房间通知
         */
        _this.leaveRoomNotify = function (leaveRoomNotify) {
            egret.log(leaveRoomNotify.userId + "离开了房间");
            this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_LEVAE_ROOM_NOTIFY, false, false, leaveRoomNotify));
        };
        /**
         * 离开房间回调函数
         */
        _this.leaveRoomRsp = function (leaveRoomRsp) {
            egret.log("自己离开了房间");
            this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_LEVAE_ROOM, false, false, leaveRoomRsp));
        };
        /**
         * 创建房间成功回调
         */
        _this.createRoomRsp = function (createRoomRsp) {
            // if (createRoomRsp.status == 200) {
            // egret.log("进入房间成功");
            this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_CREATE_ROOM, false, false, createRoomRsp));
            // } else {
            // egret.log("进入房间失败："+createRoomRsp.status);
            // }
        };
        /**
         * 踢出玩家的回调
         */
        _this.kickPlayerRsp = function (kickPlayerRsp) {
            if (kickPlayerRsp.status == 200) {
                egret.log("玩家" + kickPlayerRsp.userID + "踢出房间成功");
                this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_KICK_PLAYER, false, false, kickPlayerRsp));
            }
            else {
                egret.log("玩家" + kickPlayerRsp.userID + "踢出房间失败 status" + kickPlayerRsp.status);
            }
        };
        /**
         * 有玩家被踢出的通知
         */
        _this.KickPlayerNotify = function (KickPlayerNotify) {
            egret.log("通知玩家" + KickPlayerNotify.userId + "被踢出");
            this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_KICK_PLAYER_NOTIFY, false, false, KickPlayerNotify));
        };
        /**
         * 错误回调
         */
        _this.errorResponse = function (errCode, errMsg) {
            egret.log("errCode：" + errCode + " errMsg:" + errMsg);
            if (errCode == 1001) {
                if (errMsg != "" && errMsg.indexOf("hotel") >= 0) {
                    errCode = 1002; //这里自定义把hotel断开改为 1002
                }
            }
            var data = {
                code: errCode,
                msg: errMsg
            };
            this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_ERROR, false, false, data));
        };
        /**
         * 获取房间详情
         */
        _this.getRoomDetailResponse = function (rsp) {
            console.log("获取房间详情成功");
            this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_ROOM_DETAIL_RSP, false, false, rsp));
        };
        MatchvsData.MatchvsRep.initResponse = _this.initRsp.bind(_this);
        MatchvsData.MatchvsRep.registerUserResponse = _this.registerUserRsp.bind(_this);
        MatchvsData.MatchvsRep.loginResponse = _this.loginRsp.bind(_this);
        MatchvsData.MatchvsRep.joinRoomResponse = _this.joinRsp.bind(_this);
        MatchvsData.MatchvsRep.joinRoomNotify = _this.joinRoomNotify.bind(_this);
        MatchvsData.MatchvsRep.createRoomResponse = _this.createRoomRsp.bind(_this);
        MatchvsData.MatchvsRep.leaveRoomNotify = _this.leaveRoomNotify.bind(_this);
        MatchvsData.MatchvsRep.leaveRoomResponse = _this.leaveRoomRsp.bind(_this);
        MatchvsData.MatchvsRep.kickPlayerResponse = _this.kickPlayerRsp.bind(_this);
        MatchvsData.MatchvsRep.kickPlayerNotify = _this.KickPlayerNotify.bind(_this);
        MatchvsData.MatchvsRep.networkStateNotify = _this.networkStateNotify.bind(_this);
        //todo 添加全局的一个异常监听
        MatchvsData.MatchvsRep.errorResponse = _this.errorResponse.bind(_this);
        MatchvsData.MatchvsRep.getRoomDetailResponse = _this.getRoomDetailResponse.bind(_this);
        MatchvsData.MatchvsRep.sendEventResponse = _this.sendEventResponse.bind(_this);
        MatchvsData.MatchvsRep.sendEventNotify = _this.sendEventNotify.bind(_this);
        return _this;
    }
    Object.defineProperty(PokeMatchvsRep, "getInstance", {
        get: function () {
            if (this._instance == null) {
                this._instance = new PokeMatchvsRep();
            }
            return this._instance;
        },
        enumerable: true,
        configurable: true
    });
    /**
     * 排行榜正确回调
     */
    PokeMatchvsRep.prototype.onMsg = function (buf) {
        var buf = JSON.parse(buf);
        //var listData = this.ab2str(egret.Base64Util.decode(buf.data.dataList[0].value));
        var listData = ArrayTools.Base64Decode(buf.data.dataList[0].value);
        this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_RANK_LIST, false, false, listData));
    };
    PokeMatchvsRep.prototype.onErr = function (errCode, errMsg) {
        egret.log(errCode, errMsg);
    };
    /**
     * 有人房间状态出现异常时回调
     */
    PokeMatchvsRep.prototype.networkStateNotify = function (netnotify) {
        var event = { userID: netnotify.userID, state: netnotify.state };
        egret.log("networkStateNotify", event);
        this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_NETWORKSTATE, false, false, event));
    };
    /**
     * 发送消息回调
     */
    PokeMatchvsRep.prototype.sendEventResponse = function (sendEventRsp) {
        if (sendEventRsp.status === 200) {
            this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_SEND_EVENT_RSP, false, false, sendEventRsp));
        }
        else {
            console.log("发送消息失败 status" + sendEventRsp.status);
        }
    };
    /**
     * 收到消息通知
     */
    PokeMatchvsRep.prototype.sendEventNotify = function (eventInfo) {
        this.dispatchEvent(new egret.Event(MatchvsMessage.MATCHVS_SEND_EVENT_NOTIFY, false, false, eventInfo));
        console.log("收到消息 status" + eventInfo);
    };
    PokeMatchvsRep.prototype.ab2str = function (buf) {
        return String.fromCharCode.apply(null, new Uint8Array(buf));
    };
    return PokeMatchvsRep;
}(egret.EventDispatcher));
__reflect(PokeMatchvsRep.prototype, "PokeMatchvsRep");
var Base = (function (_super) {
    __extends(Base, _super);
    function Base() {
        return _super.call(this) || this;
    }
    Base.prototype.onError = function (e) {
        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_ERROR, this.onEvent, e);
    };
    Base.prototype.onEvent = function () {
        egret.log("错误");
    };
    return Base;
}(eui.Component));
__reflect(Base.prototype, "Base");
var BattleStageUI = (function (_super) {
    __extends(BattleStageUI, _super);
    function BattleStageUI() {
        var _this = _super.call(this) || this;
        _this.roomID = "";
        _this._topHeader = null; //顶部用户自己的头像和积分位置
        _this._topNickName = null; //顶部用户自己的头像和积分位置
        _this._topPointValue = null; //顶部用户自己的头像和积分位置
        _this._waitSendCard = null;
        _this._battleControl = null; //对战控制
        _this._playerHeadSprite = null; //对手头像和卡牌放置地方
        _this._playerTimerSprite = null;
        _this._myCardSprote = null; //我的卡牌放置容器
        _this._myCardControl = null; //我的卡牌控制
        _this._sendCardAnimal = null; //发牌动画控制类型
        _this._sendCardSprote = null; //发牌时的容器
        _this._tablecardControl = null; //new battle.TableCardControl();  	//桌子牌控制
        _this._tableCardSprite = null;
        _this._battleButtonCtl = null;
        _this._battleButtonSprote = null;
        _this._chatMsgProxy = null;
        _this._chatSprite = null;
        _this.userPlayer = [];
        return _this;
    }
    /**
     * 获取exml 中的控件
     */
    BattleStageUI.prototype.partAdded = function (partName, instance) {
        _super.prototype.partAdded.call(this, partName, instance);
        console.log("partAdded", partName, instance);
        if (partName == "headImg") {
            this._topHeader = instance;
        }
        if (partName == "wait_sendCard") {
            this._waitSendCard = instance;
        }
        if (partName == "nickName") {
            this._topNickName = instance;
        }
        if (partName == "pointValue") {
            this._topPointValue = instance;
        }
    };
    BattleStageUI.prototype.childrenCreated = function () {
        _super.prototype.childrenCreated.call(this);
        this.init();
        this.StartBattle(this.userPlayer);
    };
    /**
     * 显示顶部的用户信息
     */
    BattleStageUI.prototype.showTopUserInfo = function (user) {
        if (user) {
            this._topHeader.source = user.avator;
            this._topNickName.text = user.nickName;
            this._topPointValue.text = user.pointValue.toString();
        }
    };
    BattleStageUI.prototype.WaitSendCardHide = function () {
        this._waitSendCard.visible = false;
    };
    BattleStageUI.prototype.init = function () {
        console.info("BattleStageUI init");
        //注册网络异常监听
        network.NetworkStateCheck.getInstance().RegistNetListen(this);
        //显示用户头像
        this.showTopUserInfo(GlobalData.myUser);
        //对手头像
        this._playerHeadSprite = new egret.Sprite();
        this.addChild(this._playerHeadSprite);
        // 控制对战舞台类
        this._battleControl = new battle.BattleStageControl(this);
        //我的卡牌放置容器
        this._myCardSprote = new egret.Sprite();
        this.addChild(this._myCardSprote);
        this._myCardControl = new battle.MyCardControl();
        this._myCardControl.Init(this._myCardSprote);
        //发牌容器
        this._sendCardSprote = new egret.Sprite();
        this.addChild(this._sendCardSprote);
        this._sendCardSprote.touchChildren = false;
        this._sendCardSprote.touchEnabled = false;
        // 发牌动画类
        this._sendCardAnimal = new battle.SendCardAnimal();
        this._sendCardAnimal.Init(this._sendCardSprote);
        //倒计时
        this._playerTimerSprite = new egret.Sprite();
        this.addChild(this._playerTimerSprite);
        //桌子出牌控制
        this._tablecardControl = new battle.TableCardControl();
        this._tableCardSprite = new egret.Sprite();
        this.addChild(this._tableCardSprite);
        this._tablecardControl.Init(this._tableCardSprite);
        //按钮控制
        this._battleButtonCtl = new battle.BattleBtnControl;
        this._battleButtonSprote = new egret.Sprite();
        this.addChild(this._battleButtonSprote);
        this._battleButtonCtl.Init(this._battleButtonSprote);
        this._chatSprite = new egret.Sprite();
        this.addChild(this._chatSprite);
        this._chatSprite.touchChildren = false;
        this._chatSprite.touchEnabled = false;
        this._chatMsgProxy = new battle.ChatMsgControl();
        this._chatMsgProxy.Init(this._chatSprite);
    };
    /**
     * 做与控件无关的操作
     * 在页面切换的时候，使用SceneManager切换要传输数据，可重写onShow
     * @param {any} par {userList:Array<Player>,roomID:""}
     */
    BattleStageUI.prototype.onShow = function (par) {
        if ("userList" in par && "roomID" in par) {
            this.userPlayer = par.userList;
            this.roomID = par.roomID;
        }
        egret.log("BattleStageUI", par);
    };
    /**
     * 开始对战，要先添加用户
     */
    BattleStageUI.prototype.StartBattle = function (users) {
        egret.log("StartBattle", users);
        this.addPlayers(users);
        this._battleButtonCtl.RoomIn();
        this._battleControl.Release();
        this._battleControl.init();
        this._battleControl.startGame();
    };
    //添加用户
    BattleStageUI.prototype.addPlayers = function (users) {
        console.info("addPlayers", users);
        for (var i = 0; i < users.length; i++) {
            this._battleControl.addPlayer(users[i]);
        }
    };
    /**
     * 发牌动画
     */
    BattleStageUI.prototype.SendCard = function (player) {
        this._battleButtonCtl.HideAll();
        this._sendCardAnimal.StartAnimal(player, function () {
            // 其他隐藏,除自己的
            //全部隐藏起来等待服务器下发叫地主通知
            // if (this._battleButtonCtl.State != battle.BattleBtnControl.STATE_Qiangdizhu && this._btnProxy.State != battle.BattleBtnControl.STATE_Playing) {
            //     this._battleButtonCtl.HideAll();
            // }
        }, this);
    };
    /**
     * 显示叫地主
     */
    BattleStageUI.prototype.ShowCallLand = function (player, isme, nowscore, delaytime) {
        if (isme) {
            this._battleButtonCtl.CallLandOwner(nowscore);
        }
        else {
            this._battleButtonCtl.HideAll();
        }
        //this._battleControl.SetPlayerTime(player, delaytime);
        this._battleControl.UpdateAllCardNum();
    };
    /**
     * 结束叫地主，显示按钮和牌
     * @param {battle.Player} landplayer
     * @param {Array<number>} landlist
     * @param {battle.Player} mainplayer
     * @param {string} landscore
     *
     */
    BattleStageUI.prototype.OverCallLand = function (landplayer, landlist, mainplayer, landscore) {
        //显示底牌
        this._tablecardControl.ShowLandCard(landlist);
        //显示地主标志
        this._battleControl.SetPlayerLandFlag(landplayer.LocalTableId);
        //如果我自己是地主就显示我自己的地主标志
        this._myCardControl.SetPlayerLandFlag(landplayer.LocalTableId);
        //出牌动画重置
        this._sendCardAnimal.Release(landplayer.LocalTableId);
        //设置我的牌区域
        this._myCardControl.SetMainPlayer(mainplayer);
        //对战控制
        this._battleButtonCtl.SetCardProxy(this._myCardControl);
        //设置出牌按钮控制
        this._myCardControl.SetButtonCtl(this._battleButtonCtl);
        // TODO
        //设置倍数 todo
    };
    //轮流出牌
    BattleStageUI.prototype.TurnPlayCard = function (player, isme, isnew, tablelist, delaytime, canshowAll, lastplayer) {
        if (lastplayer === void 0) { lastplayer = null; }
        if (isnew) {
            this._sendCardAnimal.Release(0);
            this._tablecardControl.clearAll();
            this._myCardControl.SetTableList([]);
            if (lastplayer) {
                this._tablecardControl.ShowTableCard(lastplayer.LocalTableId, null);
            }
        }
        if (isme) {
            this._myCardControl.SetTableList(tablelist);
            if (lastplayer) {
                this._tablecardControl.ShowTableCard(lastplayer.LocalTableId, tablelist);
            }
            this._myCardControl.CanShowAll = canshowAll;
            var hascar = true;
            this._battleButtonCtl.Playing(isnew);
            this._myCardControl.SetBtnVisible();
            if (player.cardNumber == 1 && player.cardNumber < tablelist.length) {
                network.BattleMsg.getInstance().sendToGameServer(network.NetMsgEvent.PLAY_CARDS_S, { cardlist: [] });
                this._battleButtonCtl.HideAll();
                return;
            }
        }
        else {
            this._battleButtonCtl.HideAll();
        }
        this._battleControl.SetPlayerTime(player, delaytime);
        this._battleControl.UpdateAllCardNum();
    };
    /**
     *  有玩家出牌后，更新桌面牌
     */
    BattleStageUI.prototype.ShowPlay = function (player, clist, isme, timestr) {
        this._battleControl.UpdateAllCardNum();
        console.info("BattleStageUI ShowPlay isme:", isme);
        if (isme) {
            //如果出牌人是我，更新我的牌数量
            this._myCardControl.SendOver(clist);
        }
        if (clist != null && clist.length > 0) {
            this._tablecardControl.ShowTableCard(player.LocalTableId, clist);
            this._myCardControl.SetTableList(clist);
        }
        else {
            this._tablecardControl.ShowTableCard(player.LocalTableId, clist);
            this._chatMsgProxy.ShowTableCard(player.LocalTableId, "不要");
        }
    };
    BattleStageUI.prototype.GameOver = function (iswin, p1, p2, p3, islandwin, timestr, isactover, actrank, actHScore, actmoney, winplayer) {
        this._battleButtonCtl.HideAll();
        if (p1) {
            this._tablecardControl.ShowTableCard(1, p1.cardList);
        }
        if (p2) {
            this._tablecardControl.ShowTableCard(2, p2.cardList);
        }
        if (p3) {
            this._tablecardControl.ShowTableCard(3, p3.cardList);
            // this._myCardControl.Release();
        }
        SceneManager.JumpResultUI(p3, p1, p2, iswin, islandwin, timestr, this.roomID);
        this.Release();
        return;
    };
    BattleStageUI.prototype.ReSendCards = function () {
        this._myCardSprote.removeChildren();
        this._battleButtonCtl.HideAll();
        this._sendCardSprote.removeChildren();
    };
    BattleStageUI.prototype.Release = function () {
        this.removeChildren();
        this._battleButtonCtl && this._battleButtonCtl.Release();
        this._battleButtonCtl && this._myCardControl.Release();
        this._battleButtonCtl && this._tablecardControl.clearAll();
        this._battleButtonCtl && this._battleControl.Release();
    };
    return BattleStageUI;
}(eui.Component));
__reflect(BattleStageUI.prototype, "BattleStageUI", ["eui.UIComponent", "egret.DisplayObject"]);
var ErrorNote = (function (_super) {
    __extends(ErrorNote, _super);
    function ErrorNote() {
        var _this = _super.call(this) || this;
        _this._btn_ok = null;
        _this._lb_message = null;
        _this._btn_ok_callback = null;
        _this._error_msg = "";
        return _this;
    }
    ErrorNote.prototype.partAdded = function (partName, instance) {
        _super.prototype.partAdded.call(this, partName, instance);
        if (partName == "btn_ok") {
            this._btn_ok = instance;
        }
        if (partName == "lb_message") {
            this._lb_message = instance;
        }
    };
    ErrorNote.prototype.childrenCreated = function () {
        var _this = this;
        _super.prototype.childrenCreated.call(this);
        this._btn_ok.addEventListener(egret.TouchEvent.TOUCH_END, function (e) {
            if (_this._btn_ok_callback) {
                _this._btn_ok_callback();
            }
        }, this);
        this._lb_message.text = this._error_msg;
        //
        network.NetworkStateCheck.getInstance().RegistNetListen(this);
    };
    /**
     * @param {msg}	msg 要显示的消息
     * @param {Function} callback 按钮回调
     *
     */
    ErrorNote.prototype.SetErrorMsg = function (msg, callback) {
        this._btn_ok_callback = callback;
        this._error_msg = msg;
    };
    return ErrorNote;
}(eui.Component));
__reflect(ErrorNote.prototype, "ErrorNote", ["eui.UIComponent", "egret.DisplayObject"]);
var Game = (function (_super) {
    __extends(Game, _super);
    function Game() {
        var _this = _super.call(this) || this;
        _this.userPlayer = [];
        _this.roomName = "我是世界第一，你是谁？";
        _this.roomPropety = "谁都可以来挑战我";
        _this.isInvite = false; //是否是邀请
        Toast.initRes(_this, "resource/loading/toast-bg.png");
        return _this;
    }
    Game.prototype.partAdded = function (partName, instance) {
        _super.prototype.partAdded.call(this, partName, instance);
        //昵称
        if (partName == "nickName") {
            instance.text = GlobalData.myUser.nickName;
        }
        //积分
        if (partName == "integral") {
            instance.text = GlobalData.myUser.pointValue;
        }
        //头像
        if (partName == "head") {
            instance.source = GlobalData.myUser.avator;
        }
        instance.addEventListener(egret.TouchEvent.TOUCH_TAP, function (e) {
            //快速匹配
            if (partName == "fastMatch") {
                //设置游戏模式为随机模式
                MatchvsData.gameMode = false;
                if (PokeMatchvsEngine.getInstance.joinRandomRoom(MatchvsData.getDefaultUserProfile()) != 0) {
                    Toast.show("您随机匹配点击的太快了，请稍后");
                    return;
                }
                PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_JOINROOM_RSP, this.onEvent, this);
            }
            else if (partName == "createRoom") {
                //设置游戏模式为好友开心模式
                MatchvsData.gameMode = true;
                if (PokeMatchvsEngine.getInstance.creatRoom(this.roomName, this.roomPropety, MatchvsData.maxPlayer, MatchvsData.getDefaultUserProfile())) {
                    Toast.show("创建房间太快了，我已经跟不上了");
                }
                PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_CREATE_ROOM, this.onEvent, this);
            }
            else if (partName == "inviteFriends") {
                //todo 直接邀请
                MatchvsData.gameMode = true;
                this.isInvite = true; //进入房间直接邀请
                if (PokeMatchvsEngine.getInstance.creatRoom(this.roomName, this.roomPropety, MatchvsData.maxPlayer, MatchvsData.getDefaultUserProfile())) {
                    Toast.show("创建房间太快了，我已经跟不上了");
                }
                PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_CREATE_ROOM, this.onEvent, this);
            }
        }, this);
        network.NetworkStateCheck.getInstance().RegistNetListen(this);
    };
    /**
     * 接收Event信息
     */
    Game.prototype.onEvent = function (e) {
        switch (e.type) {
            case MatchvsMessage.MATCHVS_CREATE_ROOM:
                if (e.data.status == 200) {
                    console.log("接收到创建房间成功的消息");
                    network.BattleMsg.getInstance().sendToGameServer(network.NetMsgEvent.GAME_IS_OKS, {});
                    this.startRoomScene(e.data.roomID);
                }
                else {
                    Toast.show("创建房间失败了");
                }
                break;
            case MatchvsMessage.MATCHVS_JOINROOM_RSP:
                this.removeEvent();
                SceneManager.showScene(MatchDialog, e.data.roomID);
                break;
        }
    };
    /**
     * 移除监听
     */
    Game.prototype.removeEvent = function () {
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_CREATE_ROOM, this.onEvent, this);
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_JOINROOM_RSP, this.onEvent, this);
    };
    Game.prototype.Release = function () {
        this.removeEvent();
    };
    /**
     * 跳转到房间页面
     */
    Game.prototype.startRoomScene = function (roomID) {
        var obj = { roomID: roomID, gameMode: MatchvsData.gameMode, isInvite: this.isInvite, isRestart: true };
        this.removeEvent();
        SceneManager.showScene(Room, obj);
        this.isInvite = false;
    };
    Game.prototype.childrenCreated = function () {
        _super.prototype.childrenCreated.call(this);
        // console.log("Game","childrenCreated");
    };
    return Game;
}(eui.Component));
__reflect(Game.prototype, "Game", ["eui.UIComponent", "egret.DisplayObject"]);
var Login = (function (_super) {
    __extends(Login, _super);
    function Login() {
        var _this = _super.call(this) || this;
        _this.that = _this;
        Toast.initRes(_this, "resource/loading/toast-bg.png");
        return _this;
    }
    Login.prototype.partAdded = function (partName, instance) {
        _super.prototype.partAdded.call(this, partName, instance);
        instance.addEventListener(egret.TouchEvent.TOUCH_TAP, function (e) {
            if (partName == "btn_login") {
                if (MatchvsData.loginStatus) {
                    MatchvsData.loginStatus = false;
                    SceneManager.showScene(Game);
                }
                else {
                    Toast.show("登录失败，重试中");
                    egret.log("重新登录", GlobalData.myUser.userID + "/n" + GlobalData.myUser.token);
                    PokeMatchvsEngine.getInstance.init(MatchvsData.pChannel, MatchvsData.pPlatform, MatchvsData.gameID);
                }
            }
            else if (partName == "rank_list") {
                SceneManager.showScene(RankList);
            }
        }, this);
        network.NetworkStateCheck.getInstance().RegistNetListen(this);
    };
    Login.prototype.childrenCreated = function () {
        _super.prototype.childrenCreated.call(this);
    };
    return Login;
}(eui.Component));
__reflect(Login.prototype, "Login", ["eui.UIComponent", "egret.DisplayObject"]);
var RankList = (function (_super) {
    __extends(RankList, _super);
    // { ranking: "1", nickName: "乖宝宝", score: "10000" ,head:"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1526552548316&di=e90e3532b6906f745c2006446bd4c216&imgtype=0&src=http%3A%2F%2Fimg4.duitang.com%2Fuploads%2Fitem%2F201501%2F14%2F20150114145326_sQPjW.jpeg"}
    // , { ranking: "2", nickName: "小乖乖", score: "9852" ,head:"https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1526543170&di=1f42a59764ace471c6d9ffc50d3315ac&src=http://p.3761.com/pic/81841417221689.jpg"}
    // , { ranking: "3", nickName: "爱我不到黎明", score: "9583",head:"https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1526543170&di=15a734dd177962fd4c3c3d45295314f8&src=http://img5.duitang.com/uploads/blog/201410/06/20141006162725_FTrrj.jpeg"}
    // , { ranking: "4", nickName: "回头最寂寞", score: "6543",head: "https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1526543241&di=d3855933248104e0888253044491a25b&src=http://www.th7.cn/d/file/p/2016/12/06/410a028423831f08a3a0effd5d2e781a.jpg"}
    // , { ranking: "5", nickName: "我怕来不及", score: "5684" ,head:"https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1526543241&di=5fba65f1b8dc266ae84ef4572b78445f&src=http://www.ld12.com/upimg358/allimg/20160629/195257580739086.jpg"}
    // , { ranking: "6", nickName: "小甜蜜、幸福满溢", score: "5562",head: "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1526553605118&di=a69dcf9d481b834119bee994dabe261c&imgtype=0&src=http%3A%2F%2Fwww.qqzhi.com%2Fuploadpic%2F2015-01-29%2F231109552.jpg"}
    // , { ranking: "7", nickName: "哼゜还不是你给宠坏的", score: "4523",head: "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1526553368958&di=e726e3dbbde97b31e512b507850a2851&imgtype=0&src=http%3A%2F%2Fcdnq.duitang.com%2Fuploads%2Fitem%2F201504%2F30%2F20150430125352_aeTLk.jpeg" }
    function RankList() {
        var _this = _super.call(this) || this;
        _this.dsListHeros = [];
        var timestamp = new Date().getTime();
        PokeMatchvsEngine.getInstance.getRankList(timestamp);
        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_RANK_LIST, _this.onEvent, _this);
        return _this;
    }
    RankList.prototype.partAdded = function (partName, instance) {
        _super.prototype.partAdded.call(this, partName, instance);
        if (partName == "listGoods") {
            this.rankList = instance;
            egret.log("拿到控件");
        }
        instance.addEventListener(egret.TouchEvent.TOUCH_TAP, function (e) {
            if (partName == "close") {
                SceneManager.back();
                PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_RANK_LIST, this.onEvent, this);
            }
        }, this);
    };
    RankList.prototype.childrenCreated = function () {
        _super.prototype.childrenCreated.call(this);
    };
    RankList.prototype.onEvent = function (e) {
        switch (e.type) {
            case MatchvsMessage.MATCHVS_RANK_LIST:
                var a = JSON.parse(e.data);
                for (var i = 0; i < a.length; i++) {
                    var obj = { ranking: "", name: "", score: "", head: "" };
                    obj.ranking = (i + 1) + "";
                    if (a[i].name == "") {
                        obj.name = a[i].key;
                    }
                    else {
                        obj.name = a[i].name;
                    }
                    if (a[i].avator == "") {
                        obj.head = "http://alphazwimg.matchvs.com/egret/Three-Poker/img/images2.jpg";
                    }
                    else {
                        obj.head = a[i].avator;
                    }
                    obj.score = a[i].value;
                    this.dsListHeros.push(obj);
                }
                this.rankList.dataProvider = new eui.ArrayCollection(this.dsListHeros);
                this.rankList.itemRenderer = RankListItem;
                break;
        }
    };
    /**
     * 移除监听
     */
    RankList.prototype.removeEvent = function () {
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_RANK_LIST, this.onEvent, this);
    };
    return RankList;
}(eui.Component));
__reflect(RankList.prototype, "RankList", ["eui.UIComponent", "egret.DisplayObject"]);
var RankListItem = (function (_super) {
    __extends(RankListItem, _super);
    function RankListItem() {
        var _this = _super.call(this) || this;
        _this.rankings = [];
        return _this;
    }
    RankListItem.prototype.partAdded = function (partName, instance) {
        _super.prototype.partAdded.call(this, partName, instance);
        // if(partName == "ranking") {
        // 	egret.log(this.data) ;
        // 	if(this.data != null) {
        // 		instance.source = this.data.ranking;
        // 	}
        // }
    };
    RankListItem.prototype.createChildren = function () {
        _super.prototype.createChildren.call(this);
    };
    RankListItem.prototype.dataChanged = function () {
        _super.prototype.dataChanged.call(this);
    };
    return RankListItem;
}(eui.ItemRenderer));
__reflect(RankListItem.prototype, "RankListItem");
/**
 * 结算页面
 *
 */
var ResultUI = (function (_super) {
    __extends(ResultUI, _super);
    function ResultUI() {
        var _this = _super.call(this) || this;
        _this.allChildren = [];
        _this.roomID = "";
        _this.winTitleImg = null; //显示胜利还是失败
        _this.head_landlord = null;
        _this.head_peasant1 = null;
        _this.head_peasant2 = null;
        _this.nickName_landlord = null;
        _this.nickName_peasant1 = null;
        _this.nickName_peasant2 = null;
        _this.integral_landlord = null;
        _this.integral_peasant1 = null;
        _this.integral_peasant2 = null;
        _this.icon_landlord = null;
        _this.icon_peasant1 = null;
        _this.icon_peasant2 = null;
        _this._playerList = [];
        _this._iswin = false;
        _this._isLandWin = false;
        _this._timesCount = 0;
        _this._landlordText = "";
        _this._peasant1Text = "";
        _this._peasant2Text = "";
        _this.userInfo = [];
        return _this;
    }
    ResultUI.prototype.partAdded = function (partName, instance) {
        _super.prototype.partAdded.call(this, partName, instance);
        this.allChildren[partName] = instance;
        //egret.log("ResultUI partName",partName);
        if (partName == "confirm") {
            instance.addEventListener(egret.TouchEvent.TOUCH_TAP, function (e) {
                //确定按钮
                this.backConfirm(MatchvsData.gameMode);
            }, this);
        }
    };
    ResultUI.prototype.init = function () {
        this.winTitleImg = this.allChildren["winTitleImg"];
        this.head_landlord = this.allChildren["head_landlord"];
        this.head_peasant1 = this.allChildren["head_peasant1"];
        this.head_peasant2 = this.allChildren["head_peasant2"];
        this.nickName_landlord = this.allChildren["nickName_landlord"];
        this.nickName_peasant1 = this.allChildren["nickName_peasant1"];
        this.nickName_peasant2 = this.allChildren["nickName_peasant2"];
        this.integral_landlord = this.allChildren["integral_landlord"];
        this.integral_peasant1 = this.allChildren["integral_peasant1"];
        this.integral_peasant2 = this.allChildren["integral_peasant2"];
        this.icon_landlord = this.allChildren["icon_landlord"];
        this.icon_peasant1 = this.allChildren["icon_peasant1"];
        this.icon_peasant2 = this.allChildren["icon_peasant2"];
    };
    ResultUI.prototype.childrenCreated = function () {
        _super.prototype.childrenCreated.call(this);
        //console.log("结算页面控件获取完毕：",this.allChildren);
        //监听上报分数
        network.BattleMsg.getInstance().addEventListener(network.BattleMsgEvent.REPORT_DATA, this.ReportDataOk, this);
        network.NetworkStateCheck.getInstance().RegistNetListen(this);
    };
    ResultUI.prototype.ReportDataOk = function (ev) {
        network.BattleMsg.getInstance().removeEventListener(network.BattleMsgEvent.REPORT_DATA, this.ReportDataOk, this);
        console.info("上报分数：", ev.data);
    };
    /**
     * @param {number} base 基础值
     * @param {times} times 倍数
     * @returns {number}
     */
    ResultUI.prototype.PointIncrement = function (base, times) {
        return base * (Math.pow(2, times));
        ;
    };
    /**
     * 上报分数
     */
    ResultUI.prototype.ReporePointValue = function (v, t, m, avr, na) {
        console.info("ReporePointValue", { times: t, model: m, value: v });
        network.BattleMsg.getInstance().sendToGameServer(network.NetMsgEvent.REPROT_SCORE_S, { times: t, model: m, value: v, avator: avr, name: na });
    };
    ResultUI.prototype.reSetMyScore = function () {
        var bastBalue = 0;
        for (var i = 0; i < this._playerList.length; i++) {
            if (this._playerList[i].userID == GlobalData.myUser.userID) {
                var sco = this._playerList[i].pointValue;
                GlobalData.myUser.pointValue = sco;
            }
            if (this._playerList[i].isLandLord) {
                bastBalue = this._playerList[i].landlordScore;
            }
        }
        this.ReporePointValue(GlobalData.myUser.pointValue, bastBalue * GlobalData.baseVaue, GlobalData.ReportModel, GlobalData.myUser.avator, GlobalData.myUser.nickName);
    };
    /**
     * 计算结果值，最后结果值是变动的分数，比如地主赢，finalValue=两个农民减出来的分数
     */
    ResultUI.prototype.FinalValueResult = function (landowner, p1, p2, isLandWin, base, times) {
        var incValue = this.PointIncrement(base, times);
        var finalValue = 0;
        if (isLandWin) {
            if (p1.pointValue > incValue) {
                console.info("显示结果值1：", landowner.pointValue, p1.pointValue, p2.pointValue);
                this._peasant1Text = p1.pointValue + "-" + incValue;
                finalValue += incValue;
                p1.pointValue -= incValue;
                console.info("显示结果值2：", landowner.pointValue, p1.pointValue, p2.pointValue);
            }
            else {
                console.info("显示结果值3：", landowner.pointValue, p1.pointValue, p2.pointValue);
                this._peasant1Text = p1.pointValue + "-" + p1.pointValue;
                finalValue += Number(p1.pointValue);
                p1.pointValue = 0;
                console.info("显示结果值2：", landowner.pointValue, p1.pointValue, p2.pointValue);
            }
            if (p2.pointValue > incValue) {
                console.info("显示结果值5：", landowner.pointValue, p1.pointValue, p2.pointValue);
                finalValue += incValue;
                this._peasant2Text = p2.pointValue + "-" + incValue;
                p2.pointValue -= incValue;
                console.info("显示结果值6：", landowner.pointValue, p1.pointValue, p2.pointValue);
            }
            else {
                this._peasant2Text = p2.pointValue + "-" + p2.pointValue;
                finalValue += Number(p2.pointValue);
                p2.pointValue = 0;
            }
            this._landlordText = landowner.pointValue + "+" + Number(finalValue);
            console.info("显示结果值7：", landowner.pointValue, p1.pointValue, p2.pointValue);
            landowner.pointValue = Number(landowner.pointValue) + Number(finalValue);
            console.info("显示结果值8：", landowner.pointValue, p1.pointValue, p2.pointValue);
        }
        else {
            incValue = (incValue * 2);
            if (landowner.pointValue > incValue) {
                console.info("显示结果值9：", landowner.pointValue, p1.pointValue, p2.pointValue);
                this._landlordText = landowner.pointValue + "-" + incValue;
                landowner.pointValue -= incValue;
                finalValue += incValue;
                console.info("显示结果值10：", landowner.pointValue, p1.pointValue, p2.pointValue);
            }
            else {
                this._landlordText = landowner.pointValue + "-" + landowner.pointValue;
                finalValue += landowner.pointValue;
                landowner.pointValue = 0;
            }
            this._peasant1Text = p1.pointValue + "+" + (finalValue / 2);
            this._peasant2Text = p2.pointValue + "+" + (finalValue / 2);
            console.info("显示结果值11：", landowner.pointValue, p1.pointValue, p2.pointValue);
            p1.pointValue = Number(p1.pointValue) + Number(finalValue / 2);
            p2.pointValue = Number(p2.pointValue) + Number(finalValue / 2);
            console.info("显示结果值12：", landowner.pointValue, p1.pointValue, p2.pointValue);
        }
        var obj = { userID: landowner.userID, pointValue: landowner.pointValue };
        this.userInfo.push(obj);
        var obj1 = { userID: p1.userID, pointValue: p1.pointValue };
        this.userInfo.push(obj1);
        var obj2 = { userID: p2.userID, pointValue: p2.pointValue };
        this.userInfo.push(obj2);
        // console.info("显示结果值：",landowner,p1,p2);
        return finalValue;
    };
    /**
     * 显示结果值
     */
    ResultUI.prototype.showResult = function (landLord, peasant1, peasant2, iswin, isLandWin, timesCount, roomid) {
        this.roomID = roomid;
        //获取
        var finalValue = this.FinalValueResult(landLord, peasant1, peasant2, isLandWin, landLord.landlordScore * GlobalData.baseVaue, timesCount);
        this._playerList.push(landLord);
        this._playerList.push(peasant1);
        this._playerList.push(peasant2);
        if (iswin) {
            this.winTitleImg.source = "resource/assets/result/title_win.png";
        }
        else {
            this.winTitleImg.source = "resource/assets/result/title_fail.png";
        }
        if (isLandWin) {
            this.icon_landlord.source = "resource/assets/result/icon_result_win.png";
            this.icon_peasant1.source = "resource/assets/result/icon_result_fail.png";
            this.icon_peasant2.source = "resource/assets/result/icon_result_fail.png";
        }
        else {
            this.icon_landlord.source = "resource/assets/result/icon_result_fail.png";
            this.icon_peasant1.source = "resource/assets/result/icon_result_win.png";
            this.icon_peasant2.source = "resource/assets/result/icon_result_win.png";
        }
        this.integral_landlord.text = this._landlordText;
        this.integral_peasant1.text = this._peasant1Text;
        this.integral_peasant2.text = this._peasant2Text;
        this.head_landlord.source = landLord.avator;
        this.nickName_landlord.text = landLord.nickName;
        // var obj = {nickName:landLord.nickName,pointValue:eval(this._landlordText)};
        // this.userInfo.push(obj);
        this.head_peasant1.source = peasant1.avator;
        this.nickName_peasant1.text = peasant1.nickName;
        this.head_peasant2.source = peasant2.avator;
        this.nickName_peasant2.text = peasant2.nickName;
        //重置我的分数和上报分数到服务器
        this.reSetMyScore();
    };
    /**
     * 确定按钮
     * @param isGameMode false直接跳转到首页  true直接跳转到房间页面，userPlayer不要清空，房间需要重新打开，可以重新开始游戏
     */
    ResultUI.prototype.backConfirm = function (isGameMode) {
        if (isGameMode) {
            var obj = { roomID: this.roomID, gameMode: MatchvsData.gameMode, isInvite: false, isRestart: true, roomInfo: this.userInfo };
            SceneManager.showScene(Room, obj);
        }
        else {
            PokeMatchvsEngine.getInstance.leaveRoom("战斗结束了");
            SceneManager.showScene(Game);
        }
    };
    ResultUI.prototype.Release = function () {
        this.removeChildren();
    };
    return ResultUI;
}(eui.Component));
__reflect(ResultUI.prototype, "ResultUI", ["eui.UIComponent", "egret.DisplayObject"]);
var Room = (function (_super) {
    __extends(Room, _super);
    function Room() {
        var _this = _super.call(this) || this;
        _this.roomID = "";
        _this.countDownLabel = null;
        _this.userPlayer = [];
        _this.countDownTimer = 0; //倒计时时间
        _this.icon_one = null;
        _this.name_one = null;
        _this.icon_two = null;
        _this.name_two = null;
        _this.action = null;
        _this.action1 = null;
        _this.actionText = null;
        _this.actionText1 = null;
        _this.nickName = null;
        _this.integral = null;
        _this.head = null;
        _this.roomID_tabel = null;
        _this.my_icon = null;
        _this.my_name = null;
        _this.nameViewList = [];
        _this.iconViewList = [];
        _this.actionViewList = [];
        _this.actionTextViewList = [];
        _this.beKickedOutName = "";
        _this.restartRoomInfo = [];
        return _this;
    }
    Room.prototype.onShow = function (obj) {
        if (this.nickName != null) {
            this.showName();
        }
        console.log("Room", "onShow");
        MatchvsData.loginStatus = false;
        this.userPlayer.length = 0;
        this.roomID = obj.roomID;
        if (obj.isInvite) {
            if (MatchvsData.gameMode) {
                try {
                    var par = "roomID=" + this.roomID;
                    together("邀请好友", par);
                }
                catch (e) {
                    console.warn(e, e.message);
                }
            }
        }
        if (obj.roomInfo != undefined) {
            this.restartRoomInfo = obj.roomInfo;
        }
        if (obj.isRestart) {
            this.restart(this.roomID);
        }
    };
    Room.prototype.showName = function () {
        console.log('Room', 'showName');
        this.nickName.text = GlobalData.myUser.nickName;
        this.integral.text = GlobalData.myUser.pointValue + "";
        this.head.source = GlobalData.myUser.avator;
        this.roomID_tabel.text = "房间号：" + this.roomID;
        this.my_icon.source = GlobalData.myUser.avator;
        this.my_name.text = GlobalData.myUser.nickName;
    };
    Room.prototype.childrenCreated = function () {
        _super.prototype.childrenCreated.call(this);
        this.initEvent();
        console.log("Room", "childrenCreated");
    };
    /**
     * 重新进入房间
     */
    Room.prototype.restart = function (roomID) {
        PokeMatchvsEngine.getInstance.getRoomDetail(roomID);
        network.BattleMsg.getInstance().sendToGameServer(network.NetMsgEvent.GAME_IS_OKS, {});
    };
    Room.prototype.initEvent = function () {
        network.NetworkStateCheck.getInstance().RegistNetListen(this);
        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_KICK_PLAYER, this.onEvent, this);
        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_ROOM_DETAIL_RSP, this.onEvent, this);
        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_JOINROOM_NOTIFY, this.onEvent, this);
        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_JOINROOM_RSP, this.onEvent, this);
        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_LEVAE_ROOM_NOTIFY, this.onEvent, this);
        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_KICK_PLAYER_NOTIFY, this.onEvent, this);
        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_LEVAE_ROOM, this.onEvent, this);
        network.BattleMsg.getInstance().addEventListener(network.BattleMsgEvent.GAME_IS_OK, this.onEvent, this);
    };
    Room.prototype.partAdded = function (partName, instance) {
        _super.prototype.partAdded.call(this, partName, instance);
        console.log('Room', 'partAdded');
        switch (partName) {
            case "nickName":
                this.nickName = instance;
                instance.text = GlobalData.myUser.nickName;
                break;
            case "integral":
                this.integral = instance;
                instance.text = GlobalData.myUser.pointValue;
                break;
            case "head":
                this.head = instance;
                instance.source = GlobalData.myUser.avator;
                break;
            case "roomID_tabel":
                this.roomID_tabel = instance;
                instance.text = "房间号：" + this.roomID;
                break;
            case "my_icon":
                this.my_icon = instance;
                instance.source = GlobalData.myUser.avator;
                break;
            case "my_name":
                this.my_name = instance;
                instance.text = GlobalData.myUser.nickName;
                break;
            case "countdown":
                this.countDownLabel = instance;
                break;
            case "icon_one":
                this.icon_one = instance;
                break;
            case "name_one":
                this.name_one = instance;
                break;
            case "icon_two":
                this.icon_two = instance;
                break;
            case "name_two":
                this.name_two = instance;
                break;
            case "action":
                this.action = instance;
                break;
            case "action1":
                this.action1 = instance;
                break;
            case "action_text":
                this.actionText = instance;
                break;
            case "action_text_one":
                this.actionText1 = instance;
                break;
        }
        instance.addEventListener(egret.TouchEvent.TOUCH_TAP, function (e) {
            if (partName == "btn_leave_room") {
                PokeMatchvsEngine.getInstance.leaveRoom(MatchvsData.getDefaultUserProfile());
            }
            //踢人或者邀请
            if (partName == "action") {
                this.userAction(this.name_one);
            }
            if (partName == "action1") {
                this.userAction(this.name_two);
            }
            if (partName == "action_text") {
                this.userAction(this.name_one);
            }
            if (partName == "action_text_one") {
                this.userAction(this.name_two);
            }
        }, this);
    };
    /**
     * 接收消息
     */
    Room.prototype.onEvent = function (e) {
        switch (e.type) {
            //有人进来就通知
            case MatchvsMessage.MATCHVS_JOINROOM_NOTIFY:
                this.addUser(e.data);
                break;
            //自己加入房间的通知
            case MatchvsMessage.MATCHVS_JOINROOM_RSP:
                egret.log("我进入房间了", e.data);
                break;
            case MatchvsMessage.MATCHVS_LEVAE_ROOM_NOTIFY:
                //获取数组下标，删除离开玩家的指定的下标，将定时器重置，倒计时也需要重置
                this.removeView(e.data);
                if (e.data.owner !== GlobalData.myUser.userID) {
                    this.isOwnew(false);
                }
                else {
                    this.isOwnew(true);
                }
                break;
            case MatchvsMessage.MATCHVS_LEVAE_ROOM:
                //自己离开了房间，将定时器关闭
                if (this.timer != null) {
                    this.timer.stop();
                }
                this.userPlayer.length = 0;
                this.removeEvent();
                SceneManager.showScene(Game);
                break;
            case MatchvsMessage.MATCHVS_KICK_PLAYER_NOTIFY:
                console.log('Room');
                console.log('Room', JSON.stringify(e.data) + "2");
                this.removeView(e.data);
                if (e.data.owner !== GlobalData.myUser.userID) {
                    this.isOwnew(false);
                }
                else {
                    this.isOwnew(true);
                }
                break;
            case MatchvsMessage.MATCHVS_KICK_PLAYER:
                this.removeView(e.data);
                break;
            case MatchvsMessage.MATCHVS_ROOM_DETAIL_RSP:
                this.userPlayer = [];
                for (var i in e.data.userInfos) {
                    if (e.data.userInfos[i].userId != GlobalData.myUser.userID) {
                        this.addUser(e.data.userInfos[i]);
                    }
                }
                if (e.data.owner !== GlobalData.myUser.userID) {
                    this.isOwnew(false);
                }
                else {
                    this.isOwnew(true);
                }
                break;
            case network.BattleMsgEvent.GAME_IS_OK:
                console.log("gameServer 通知倒计时开始");
                this.createTimer();
                break;
        }
    };
    /**
     * 在这里移除所有的监听
     */
    Room.prototype.removeEvent = function () {
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_ROOM_DETAIL_RSP, this.onEvent, this);
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_JOINROOM_NOTIFY, this.onEvent, this);
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_JOINROOM_RSP, this.onEvent, this);
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_LEVAE_ROOM_NOTIFY, this.onEvent, this);
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_LEVAE_ROOM, this.onEvent, this);
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_KICK_PLAYER_NOTIFY, this.onEvent, this);
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_KICK_PLAYER, this.onEvent, this);
        network.BattleMsg.getInstance().removeEventListener(network.BattleMsgEvent.GAME_IS_OK, this.onEvent, this);
    };
    Room.prototype.Release = function () {
        this.removeEvent();
        if (this.timer != undefined) {
            this.timer.stop();
        }
    };
    /**
     * 显示其他玩家的基本信息
     */
    Room.prototype.initView = function (userPlayer) {
        egret.log("展示其他玩家信息", userPlayer.nickName);
        this.nameViewList = [this.name_one, this.name_two];
        this.iconViewList = [this.icon_one, this.icon_two];
        this.actionViewList = [this.action, this.action1];
        this.actionTextViewList = [this.actionText, this.actionText1];
        for (var i = 0; i < this.nameViewList.length; i++) {
            if (this.nameViewList[i].text == "") {
                this.nameViewList[i].text = userPlayer.nickName;
                this.iconViewList[i].source = userPlayer.avator;
                this.actionViewList[i].strokeColor = "11169372";
                this.actionTextViewList[i].text = "踢人";
                this.actionTextViewList[i].textColor = "11169372";
                return;
            }
        }
    };
    /**
     * 玩家退出将玩家的信息从页面上消失
     */
    Room.prototype.removeView = function (data) {
        console.log('Room', JSON.stringify(data));
        this.countDownLabel.text = "";
        this.countDownTimer = 0;
        var id;
        if (data.userId == undefined) {
            id = data.userID;
        }
        else {
            id = data.userId;
        }
        if (this.timer != null) {
            this.timer.stop();
        }
        for (var a = 0; a < this.userPlayer.length; a++) {
            if (id == this.userPlayer[a].userID) {
                this.userPlayer.splice(a, 1);
            }
        }
        if (id === GlobalData.myUser.userID) {
            this.countDownLabel.text = "";
            this.countDownTimer = 0;
            this.removeEvent();
            SceneManager.showScene(Game);
        }
        var name;
        if (this.beKickedOutName == "") {
            var arr = JSON.parse(data.cpProto);
            name = arr.nickName;
        }
        else {
            name = this.beKickedOutName;
        }
        for (var i = 0; i < this.nameViewList.length; i++) {
            if (name == this.nameViewList[i].text) {
                this.nameViewList[i].text = "";
                this.iconViewList[i].source = "";
                this.actionViewList[i].strokeColor = "15445580";
                this.actionTextViewList[i].text = "邀请";
                this.actionTextViewList[i].textColor = "15445580";
                //11169372
                this.beKickedOutName = "";
                return;
            }
        }
    };
    /**
     * 用户操作，踢人或者邀请
     */
    Room.prototype.userAction = function (instance) {
        var name = instance.text;
        console.log("正在操作名字为" + name + "玩家");
        if (name != "" && name != undefined) {
            //踢人
            for (var i = 0; i < this.userPlayer.length; i++) {
                if (name === this.userPlayer[i].nickName) {
                    PokeMatchvsEngine.getInstance.kickPlayer(this.userPlayer[i].userID, name);
                }
            }
            this.beKickedOutName = instance.text;
        }
        else {
            try {
                var par = "roomID=" + this.roomID;
                together("约战", par);
            }
            catch (e) {
                console.warn(e, e.message);
            }
        }
    };
    //创建一个定时器
    Room.prototype.createTimer = function () {
        this.timer = new egret.Timer(1000, 11);
        //注册事件侦听器
        this.timer.addEventListener(egret.TimerEvent.TIMER, this.showCounDownLabel, this);
        this.timer.start();
    };
    /**
     * 显示开始游戏倒计时
     */
    Room.prototype.showCounDownLabel = function () {
        this.countDownLabel.text = "开始倒计时：" + Math.abs((this.countDownTimer - 10));
        this.countDownTimer++;
        if (this.countDownTimer === 11) {
            this.timer.stop();
            this.startBattle();
        }
    };
    /**
      * 跳转游戏页面
    */
    Room.prototype.startBattle = function () {
        MatchvsData.gameMode = true;
        this.userPlayer.push(GlobalData.myUser);
        this.removeEvent();
        var obj = { roomID: this.roomID, userList: this.userPlayer };
        SceneManager.showScene(BattleStageUI, obj);
    };
    /**
     * 将玩家信息放入UserplayerList中
     */
    Room.prototype.addUser = function (userPlayer) {
        var user = new GUser;
        var arr = JSON.parse(userPlayer.userProfile);
        console.log(arr.nickName + '有' + arr.pointValue + 'id是' + userPlayer.userID);
        user.nickName = arr.nickName;
        user.avator = arr.avator;
        console.log('第二次传过来的信息' + JSON.stringify(this.restartRoomInfo));
        if (this.restartRoomInfo.length > 0) {
            for (var a = 0; a < this.restartRoomInfo.length; a++) {
                console.log('a是：' + a);
                console.log('我的id是' + userPlayer.userID, '对比的id是' + this.restartRoomInfo[a].userID);
                if (userPlayer.userID == this.restartRoomInfo[a].userID) {
                    user.pointValue = this.restartRoomInfo[a].pointValue;
                    console.log('第二次重新开始，我的分数是' + this.restartRoomInfo[a].pointValue);
                }
            }
        }
        else {
            user.pointValue = arr.pointValue;
            console.log('初始分数' + arr.pointValue);
        }
        user.userID = userPlayer.userId;
        this.initView(user);
        this.userPlayer.push(user);
    };
    /**
     * 是否是房主,是房主 传true 不是传 false，来确定按钮的显示隐藏
     */
    Room.prototype.isOwnew = function (isOwnew) {
        this.action.visible = isOwnew;
        this.action1.visible = isOwnew;
        this.actionText.visible = isOwnew;
        this.actionText1.visible = isOwnew;
    };
    return Room;
}(eui.Component));
__reflect(Room.prototype, "Room", ["eui.UIComponent", "egret.DisplayObject"]);
var TopHeader = (function (_super) {
    __extends(TopHeader, _super);
    function TopHeader() {
        var _this = _super.call(this) || this;
        _this.allChildren = [];
        _this._headerImg = null;
        _this._nickName = null;
        _this._pointValue = null;
        return _this;
    }
    /**
     * 获取Exml 文件内容
     */
    TopHeader.prototype.partAdded = function (partName, instance) {
        _super.prototype.partAdded.call(this, partName, instance);
        this.allChildren[partName] = instance;
        egret.log("获取控件");
    };
    TopHeader.prototype.init = function () {
        egret.log("使用控件");
        this._headerImg = this.allChildren["headImg"];
        this._nickName = this.allChildren["nickName"];
        this._pointValue = this.allChildren["pointValue"];
    };
    /**
     * 设置头像
     */
    TopHeader.prototype.ShowAvator = function (avator) {
        if (this._headerImg) {
            this._headerImg.source = avator;
        }
    };
    /**
     * 设置昵称
     */
    TopHeader.prototype.SetNickName = function (name) {
        if (this._nickName) {
            this._nickName.text = name;
        }
    };
    /**
     * 设置积分
     */
    TopHeader.prototype.SetPointValue = function (value) {
        if (this._pointValue) {
            this._pointValue.text = value.toString();
        }
    };
    return TopHeader;
}(eui.Component));
__reflect(TopHeader.prototype, "TopHeader", ["eui.UIComponent", "egret.DisplayObject"]);
var BlockBasic = (function () {
    function BlockBasic(x, y, idx, color, shapes) {
        this.x = x;
        this.y = y;
        this.idx = idx;
        this.color = color;
        this.shapes = shapes;
    }
    ;
    return BlockBasic;
}());
__reflect(BlockBasic.prototype, "BlockBasic");
/*
 *
 * @author
 *
 */
var ArrayTools = (function () {
    function ArrayTools() {
    }
    //随机打乱数组
    ArrayTools.RandomSort = function (list) {
        list.sort(function () {
            return Math.random() - 0.5;
        });
    };
    //数组排序
    ArrayTools.Sort = function (list) {
        list.sort(function (a, b) {
            return a - b;
        });
    };
    ArrayTools.UTF16ToUTF8 = function (str) {
        var res = [], len = str.length;
        for (var i = 0; i < len; i++) {
            var code = str.charCodeAt(i);
            if (code > 0x0000 && code <= 0x007F) {
                // 单字节，这里并不考虑0x0000，因为它是空字节
                // U+00000000 – U+0000007F 	0xxxxxxx
                res.push(str.charAt(i));
            }
            else if (code >= 0x0080 && code <= 0x07FF) {
                // 双字节
                // U+00000080 – U+000007FF 	110xxxxx 10xxxxxx
                // 110xxxxx
                var byte1 = 0xC0 | ((code >> 6) & 0x1F);
                // 10xxxxxx
                var byte2 = 0x80 | (code & 0x3F);
                res.push(String.fromCharCode(byte1), String.fromCharCode(byte2));
            }
            else if (code >= 0x0800 && code <= 0xFFFF) {
                // 三字节
                // U+00000800 – U+0000FFFF 	1110xxxx 10xxxxxx 10xxxxxx
                // 1110xxxx
                var byte1 = 0xE0 | ((code >> 12) & 0x0F);
                // 10xxxxxx
                var byte2 = 0x80 | ((code >> 6) & 0x3F);
                // 10xxxxxx
                var byte3 = 0x80 | (code & 0x3F);
                res.push(String.fromCharCode(byte1), String.fromCharCode(byte2), String.fromCharCode(byte3));
            }
            else if (code >= 0x00010000 && code <= 0x001FFFFF) {
                // 四字节
                // U+00010000 – U+001FFFFF 	11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
            }
            else if (code >= 0x00200000 && code <= 0x03FFFFFF) {
                // 五字节
                // U+00200000 – U+03FFFFFF 	111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
            }
            else {
                // 六字节
                // U+04000000 – U+7FFFFFFF 	1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
            }
        }
        return res.join('');
    };
    ArrayTools.UTF8ToUTF16 = function (str) {
        var res = [], len = str.length;
        var i = 0;
        for (var i = 0; i < len; i++) {
            var code = str.charCodeAt(i);
            // 对第一个字节进行判断
            if (((code >> 7) & 0xFF) == 0x0) {
                // 单字节
                // 0xxxxxxx
                res.push(str.charAt(i));
            }
            else if (((code >> 5) & 0xFF) == 0x6) {
                // 双字节
                // 110xxxxx 10xxxxxx
                var code2 = str.charCodeAt(++i);
                var byte1 = (code & 0x1F) << 6;
                var byte2 = code2 & 0x3F;
                var utf16 = byte1 | byte2;
                res.push(String.fromCharCode(utf16));
            }
            else if (((code >> 4) & 0xFF) == 0xE) {
                // 三字节
                // 1110xxxx 10xxxxxx 10xxxxxx
                var code2 = str.charCodeAt(++i);
                var code3 = str.charCodeAt(++i);
                var byte1 = (code << 4) | ((code2 >> 2) & 0x0F);
                var byte2 = ((code2 & 0x03) << 6) | (code3 & 0x3F);
                var utf16 = ((byte1 & 0x00FF) << 8) | byte2;
                res.push(String.fromCharCode(utf16));
            }
            else if (((code >> 3) & 0xFF) == 0x1E) {
                // 四字节
                // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
            }
            else if (((code >> 2) & 0xFF) == 0x3E) {
                // 五字节
                // 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
            }
            else {
                // 六字节
                // 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
            }
        }
        return res.join('');
    };
    ArrayTools.Base64Encode = function (str) {
        if (!str) {
            return '';
        }
        var utf8 = this.UTF16ToUTF8(str); // 转成UTF8
        var i = 0; // 遍历索引
        var len = utf8.length;
        var res = [];
        while (i < len) {
            var c1 = utf8.charCodeAt(i++) & 0xFF;
            res.push(this.table[c1 >> 2]);
            // 需要补2个=
            if (i == len) {
                res.push(this.table[(c1 & 0x3) << 4]);
                res.push('==');
                break;
            }
            var c2 = utf8.charCodeAt(i++);
            // 需要补1个=
            if (i == len) {
                res.push(this.table[((c1 & 0x3) << 4) | ((c2 >> 4) & 0x0F)]);
                res.push(this.table[(c2 & 0x0F) << 2]);
                res.push('=');
                break;
            }
            var c3 = utf8.charCodeAt(i++);
            res.push(this.table[((c1 & 0x3) << 4) | ((c2 >> 4) & 0x0F)]);
            res.push(this.table[((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6)]);
            res.push(this.table[c3 & 0x3F]);
        }
        return res.join('');
    };
    ArrayTools.Base64Decode = function (str) {
        if (!str) {
            return '';
        }
        var len = str.length;
        var i = 0;
        var res = [];
        var code1 = 0;
        var code2 = 0;
        var code3 = 0;
        var code4 = 0;
        while (i < len) {
            code1 = this.table.indexOf(str.charAt(i++));
            code2 = this.table.indexOf(str.charAt(i++));
            code3 = this.table.indexOf(str.charAt(i++));
            code4 = this.table.indexOf(str.charAt(i++));
            var c1 = (code1 << 2) | (code2 >> 4);
            res.push(String.fromCharCode(c1));
            if (code3 != -1) {
                var c2 = ((code2 & 0xF) << 4) | (code3 >> 2);
                res.push(String.fromCharCode(c2));
            }
            if (code4 != -1) {
                var c3 = ((code3 & 0x3) << 6) | code4;
                res.push(String.fromCharCode(c3));
            }
        }
        return this.UTF8ToUTF16(res.join(''));
    };
    /**
    * UTF16和UTF8转换对照表
    * U+00000000 – U+0000007F 	0xxxxxxx
    * U+00000080 – U+000007FF 	110xxxxx 10xxxxxx
    * U+00000800 – U+0000FFFF 	1110xxxx 10xxxxxx 10xxxxxx
    * U+00010000 – U+001FFFFF 	11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
    * U+00200000 – U+03FFFFFF 	111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
    * U+04000000 – U+7FFFFFFF 	1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
    */
    // 转码表
    ArrayTools.table = [
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
        'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
        'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
        'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
        'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
        'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
        'w', 'x', 'y', 'z', '0', '1', '2', '3',
        '4', '5', '6', '7', '8', '9', '+', '/'
    ];
    return ArrayTools;
}());
__reflect(ArrayTools.prototype, "ArrayTools");
var IntegralSettlement = (function () {
    function IntegralSettlement() {
    }
    return IntegralSettlement;
}());
__reflect(IntegralSettlement.prototype, "IntegralSettlement");
var MatchDialog = (function (_super) {
    __extends(MatchDialog, _super);
    function MatchDialog(obj) {
        var _this = _super.call(this) || this;
        _this.defaultFont = 0;
        _this.fontImgUnits = null;
        _this.fontImgtens = null;
        _this.fontImghundreds = null;
        _this.userPlayer = [];
        _this.roomID = "";
        _this.Num = [9, 99, 999, 9999, 9999, 99999, 999999];
        console.log('MatchDialog', 'constructor');
        _this.roomID = obj;
        _this.timer = new egret.Timer(1000, 0);
        //注册事件侦听器
        _this.timer.addEventListener(egret.TimerEvent.TIMER, _this.timerFunc, _this);
        _this.timer.start();
        _this.userPlayer.length = 0;
        return _this;
    }
    MatchDialog.prototype.initEvent = function () {
        console.log("initEvent");
        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_JOINROOM_NOTIFY, this.onEvent, this);
        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_LEVAE_ROOM, this.onEvent, this);
        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_LEVAE_ROOM_NOTIFY, this.onEvent, this);
        PokeMatchvsRep.getInstance.addEventListener(MatchvsMessage.MATCHVS_ROOM_DETAIL_RSP, this.onEvent, this);
    };
    MatchDialog.prototype.partAdded = function (partName, instance) {
        _super.prototype.partAdded.call(this, partName, instance);
        if (partName == "time_units") {
            this.fontImgUnits = instance;
        }
        if (partName == "time_tens") {
            this.fontImgtens = instance;
        }
        if (partName == "time_hundreds") {
            this.fontImghundreds = instance;
        }
        if (partName == "cancel_match") {
            instance.addEventListener(egret.TouchEvent.TOUCH_TAP, function (e) {
                if (PokeMatchvsEngine.getInstance.leaveRoom("不想等待匹配了") == -6) {
                    this.userPlayer.length = 0;
                    this.stopTimer();
                    SceneManager.showScene(Game);
                }
            }, this);
        }
        ;
        network.NetworkStateCheck.getInstance().RegistNetListen(this);
    };
    MatchDialog.prototype.childrenCreated = function () {
        _super.prototype.childrenCreated.call(this);
        console.log('MatchDialog', 'childrenCreated');
        network.NetworkStateCheck.getInstance().RegistNetListen(this);
        PokeMatchvsEngine.getInstance.getRoomDetail(this.roomID);
        this.initEvent();
    };
    /**
     * 接收Event信息
     */
    MatchDialog.prototype.onEvent = function (e) {
        switch (e.type) {
            case MatchvsMessage.MATCHVS_ROOM_DETAIL_RSP:
                for (var i in e.data.userInfos) {
                    if (e.data.userInfos[i].userId != GlobalData.myUser.userID) {
                        this.addUser(e.data.userInfos[i]);
                    }
                }
                break;
            case MatchvsMessage.MATCHVS_JOINROOM_NOTIFY:
                this.addUser(e.data);
                break;
            case MatchvsMessage.MATCHVS_LEVAE_ROOM_NOTIFY:
                //获取数组下标，删除离开玩家的指定的下标，将定时器重置，倒计时也需要重置
                for (var i in this.userPlayer) {
                    if (e.data.userId == this.userPlayer[i].userID) {
                        egret.log("删除userID在数组的位置" + i);
                        this.userPlayer.splice(parseInt(i), 1);
                    }
                }
                break;
            case MatchvsMessage.MATCHVS_LEVAE_ROOM:
                this.userPlayer.length = 0;
                egret.log("接收到离开房间的消息");
                this.stopTimer();
                // var roomPanel = new Game();
                // this.addChild(roomPanel);
                // roomPanel = null;
                SceneManager.back();
                console.log('MatchDialog', 'back_game');
                break;
        }
    };
    /**
     * 跳转游戏页面
     */
    MatchDialog.prototype.startBattle = function () {
        this.stopTimer();
        var obj = { roomID: this.roomID, userList: this.userPlayer };
        SceneManager.showScene(BattleStageUI, obj);
    };
    /**
     * 定时器时间的展示
     */
    MatchDialog.prototype.timerFunc = function () {
        switch (this.defaultFont.toString().length) {
            case 1:
                var a = this.defaultFont % 10;
                this.fontImgUnits.source = (a).toString();
                break;
            case 2:
                var a = this.defaultFont % 10;
                var b = Math.floor((this.defaultFont % 100) / 10);
                this.fontImgUnits.source = a.toString();
                this.fontImgtens.source = b.toString();
                break;
            case 3:
                var a = this.defaultFont % 10;
                var b = Math.floor((this.defaultFont % 100) / 10);
                var c = Math.floor((this.defaultFont / 100));
                this.fontImgUnits.source = (a).toString();
                this.fontImgtens.source = (b).toString();
                this.fontImghundreds.source = (c).toString();
                break;
        }
        egret.log("时间" + this.defaultFont);
        this.defaultFont++;
    };
    /**
 * 将玩家信息放入UserplayerList中
 */
    MatchDialog.prototype.addUser = function (userPlayer) {
        if (this.userPlayer.length > 0) {
            for (var i = 0; i < this.userPlayer.length; i++) {
                if (userPlayer.userId != this.userPlayer[i].userID) {
                    var user = new GUser;
                    var arr = JSON.parse(userPlayer.userProfile);
                    user.nickName = arr.nickName;
                    user.avator = arr.avator;
                    user.pointValue = arr.pointValue;
                    user.userID = userPlayer.userId;
                    this.userPlayer.push(user);
                }
            }
        }
        else {
            var user = new GUser;
            var arr = JSON.parse(userPlayer.userProfile);
            user.nickName = arr.nickName;
            user.avator = arr.avator;
            user.pointValue = arr.pointValue;
            user.userID = userPlayer.userId;
            this.userPlayer.push(user);
        }
        egret.log("userPlayer的长度" + this.userPlayer.length);
        if (this.userPlayer.length == (MatchvsData.maxPlayer - 1)) {
            this.userPlayer.push(GlobalData.myUser);
            this.startBattle();
        }
    };
    /**
     * 将定时器停止,移除监听
     */
    MatchDialog.prototype.stopTimer = function () {
        this.removeEvent();
        this.timer.stop();
    };
    MatchDialog.prototype.removeEvent = function () {
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_JOINROOM_NOTIFY, this.onEvent, this);
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_LEVAE_ROOM_NOTIFY, this.onEvent, this);
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_LEVAE_ROOM, this.onEvent, this);
        PokeMatchvsRep.getInstance.removeEventListener(MatchvsMessage.MATCHVS_ROOM_DETAIL_RSP, this.onEvent, this);
        this.timer.removeEventListener(egret.TimerEvent.TIMER, this.timerFunc, this);
    };
    MatchDialog.prototype.Release = function () {
        this.removeEvent();
    };
    MatchDialog.prototype.getIntLenth = function (x) {
        for (var i = 0; i < this.Num.length; i++) {
            if (Math.abs(x) <= this.Num[i]) {
                return i + 1;
            }
        }
    };
    return MatchDialog;
}(eui.Component));
__reflect(MatchDialog.prototype, "MatchDialog", ["eui.UIComponent", "egret.DisplayObject"]);
/**
 * MD5加密
 */
var MD5 = (function () {
    function MD5() {
        this.hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase        */
        this.b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance   */
    }
    /*
    * These are the privates you'll usually want to call
    * They take string arguments and return either hex or base-64 encoded strings
    */
    MD5.prototype.hex_md5 = function (s) { return this.rstr2hex(this.rstr_md5(this.str2rstr_utf8(s))); }; //这个函数就行了，  
    MD5.prototype.b64_md5 = function (s) { return this.rstr2b64(this.rstr_md5(this.str2rstr_utf8(s))); };
    MD5.prototype.any_md5 = function (s, e) { return this.rstr2any(this.rstr_md5(this.str2rstr_utf8(s)), e); };
    MD5.prototype.hex_hmac_md5 = function (k, d) { return this.rstr2hex(this.rstr_hmac_md5(this.str2rstr_utf8(k), this.str2rstr_utf8(d))); };
    MD5.prototype.b64_hmac_md5 = function (k, d) { return this.rstr2b64(this.rstr_hmac_md5(this.str2rstr_utf8(k), this.str2rstr_utf8(d))); };
    MD5.prototype.any_hmac_md5 = function (k, d, e) { return this.rstr2any(this.rstr_hmac_md5(this.str2rstr_utf8(k), this.str2rstr_utf8(d)), e); };
    /*
    * Perform a simple self-test to see if the VM is working
    */
    MD5.prototype.md5_vm_test = function () {
        return this.hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72";
    };
    /*
    * Calculate the MD5 of a raw string
    */
    MD5.prototype.rstr_md5 = function (s) {
        return this.binl2rstr(this.binl_md5(this.rstr2binl(s), s.length * 8));
    };
    /*
    * Calculate the HMAC-MD5, of a key and some data (raw strings)
    */
    MD5.prototype.rstr_hmac_md5 = function (key, data) {
        var bkey = this.rstr2binl(key);
        if (bkey.length > 16)
            bkey = this.binl_md5(bkey, key.length * 8);
        var ipad = Array(16), opad = Array(16);
        for (var i = 0; i < 16; i++) {
            ipad[i] = bkey[i] ^ 0x36363636;
            opad[i] = bkey[i] ^ 0x5C5C5C5C;
        }
        var hash = this.binl_md5(ipad.concat(this.rstr2binl(data)), 512 + data.length * 8);
        return this.binl2rstr(this.binl_md5(opad.concat(hash), 512 + 128));
    };
    /*
    * Convert a raw string to a hex string
    */
    MD5.prototype.rstr2hex = function (input) {
        try {
            this.hexcase;
        }
        catch (e) {
            this.hexcase = 0;
        }
        var hex_tab = this.hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
        var output = "";
        var x;
        for (var i = 0; i < input.length; i++) {
            x = input.charCodeAt(i);
            output += hex_tab.charAt((x >>> 4) & 0x0F)
                + hex_tab.charAt(x & 0x0F);
        }
        return output;
    };
    /*
    * Convert a raw string to a base-64 string
    */
    MD5.prototype.rstr2b64 = function (input) {
        try {
            this.b64pad;
        }
        catch (e) {
            this.b64pad = '';
        }
        var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
        var output = "";
        var len = input.length;
        for (var i = 0; i < len; i += 3) {
            var triplet = (input.charCodeAt(i) << 16)
                | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0)
                | (i + 2 < len ? input.charCodeAt(i + 2) : 0);
            for (var j = 0; j < 4; j++) {
                if (i * 8 + j * 6 > input.length * 8)
                    output += this.b64pad;
                else
                    output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F);
            }
        }
        return output;
    };
    /*
    * Convert a raw string to an arbitrary string encoding
    */
    MD5.prototype.rstr2any = function (input, encoding) {
        var divisor = encoding.length;
        var i, j, q, x, quotient;
        /* Convert to an array of 16-bit big-endian values, forming the dividend */
        var dividend = Array(Math.ceil(input.length / 2));
        for (i = 0; i < dividend.length; i++) {
            dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1);
        }
        /*
        * Repeatedly perform a long division. The binary array forms the dividend,
        * the length of the encoding is the divisor. Once computed, the quotient
        * forms the dividend for the next step. All remainders are stored for later
        * use.
        */
        var full_length = Math.ceil(input.length * 8 /
            (Math.log(encoding.length) / Math.log(2)));
        var remainders = Array(full_length);
        for (j = 0; j < full_length; j++) {
            quotient = Array();
            x = 0;
            for (i = 0; i < dividend.length; i++) {
                x = (x << 16) + dividend[i];
                q = Math.floor(x / divisor);
                x -= q * divisor;
                if (quotient.length > 0 || q > 0)
                    quotient[quotient.length] = q;
            }
            remainders[j] = x;
            dividend = quotient;
        }
        /* Convert the remainders to the output string */
        var output = "";
        for (i = remainders.length - 1; i >= 0; i--)
            output += encoding.charAt(remainders[i]);
        return output;
    };
    /*
    * Encode a string as utf-8.
    * For efficiency, this assumes the input is valid utf-16.
    */
    MD5.prototype.str2rstr_utf8 = function (input) {
        var output = "";
        var i = -1;
        var x, y;
        while (++i < input.length) {
            /* Decode utf-16 surrogate pairs */
            x = input.charCodeAt(i);
            y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0;
            if (0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) {
                x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF);
                i++;
            }
            /* Encode output as utf-8 */
            if (x <= 0x7F)
                output += String.fromCharCode(x);
            else if (x <= 0x7FF)
                output += String.fromCharCode(0xC0 | ((x >>> 6) & 0x1F), 0x80 | (x & 0x3F));
            else if (x <= 0xFFFF)
                output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), 0x80 | ((x >>> 6) & 0x3F), 0x80 | (x & 0x3F));
            else if (x <= 0x1FFFFF)
                output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), 0x80 | ((x >>> 12) & 0x3F), 0x80 | ((x >>> 6) & 0x3F), 0x80 | (x & 0x3F));
        }
        return output;
    };
    /*
    * Encode a string as utf-16
    */
    MD5.prototype.str2rstr_utf16le = function (input) {
        var output = "";
        for (var i = 0; i < input.length; i++)
            output += String.fromCharCode(input.charCodeAt(i) & 0xFF, (input.charCodeAt(i) >>> 8) & 0xFF);
        return output;
    };
    MD5.prototype.str2rstr_utf16be = function (input) {
        var output = "";
        for (var i = 0; i < input.length; i++)
            output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, input.charCodeAt(i) & 0xFF);
        return output;
    };
    /*
    * Convert a raw string to an array of little-endian words
    * Characters >255 have their high-byte silently ignored.
    */
    MD5.prototype.rstr2binl = function (input) {
        var output = Array(input.length >> 2);
        for (var i = 0; i < output.length; i++)
            output[i] = 0;
        for (var i = 0; i < input.length * 8; i += 8)
            output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (i % 32);
        return output;
    };
    /*
    * Convert an array of little-endian words to a string
    */
    MD5.prototype.binl2rstr = function (input) {
        var output = "";
        for (var i = 0; i < input.length * 32; i += 8)
            output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xFF);
        return output;
    };
    /*
    * Calculate the MD5 of an array of little-endian words, and a bit length.
    */
    MD5.prototype.binl_md5 = function (x, len) {
        /* append padding */
        x[len >> 5] |= 0x80 << ((len) % 32);
        x[(((len + 64) >>> 9) << 4) + 14] = len;
        var a = 1732584193;
        var b = -271733879;
        var c = -1732584194;
        var d = 271733878;
        for (var i = 0; i < x.length; i += 16) {
            var olda = a;
            var oldb = b;
            var oldc = c;
            var oldd = d;
            a = this.md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
            d = this.md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
            c = this.md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
            b = this.md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
            a = this.md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
            d = this.md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
            c = this.md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
            b = this.md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
            a = this.md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
            d = this.md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
            c = this.md5_ff(c, d, a, b, x[i + 10], 17, -42063);
            b = this.md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
            a = this.md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
            d = this.md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
            c = this.md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
            b = this.md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
            a = this.md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
            d = this.md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
            c = this.md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
            b = this.md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
            a = this.md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
            d = this.md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
            c = this.md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
            b = this.md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
            a = this.md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
            d = this.md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
            c = this.md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
            b = this.md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
            a = this.md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
            d = this.md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
            c = this.md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
            b = this.md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
            a = this.md5_hh(a, b, c, d, x[i + 5], 4, -378558);
            d = this.md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
            c = this.md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
            b = this.md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
            a = this.md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
            d = this.md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
            c = this.md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
            b = this.md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
            a = this.md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
            d = this.md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
            c = this.md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
            b = this.md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
            a = this.md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
            d = this.md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
            c = this.md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
            b = this.md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
            a = this.md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
            d = this.md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
            c = this.md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
            b = this.md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
            a = this.md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
            d = this.md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
            c = this.md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
            b = this.md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
            a = this.md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
            d = this.md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
            c = this.md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
            b = this.md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
            a = this.md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
            d = this.md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
            c = this.md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
            b = this.md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
            a = this.safe_add(a, olda);
            b = this.safe_add(b, oldb);
            c = this.safe_add(c, oldc);
            d = this.safe_add(d, oldd);
        }
        return [a, b, c, d];
    };
    /*
    * These privates implement the four basic operations the algorithm uses.
    */
    MD5.prototype.md5_cmn = function (q, a, b, x, s, t) {
        return this.safe_add(this.bit_rol(this.safe_add(this.safe_add(a, q), this.safe_add(x, t)), s), b);
    };
    MD5.prototype.md5_ff = function (a, b, c, d, x, s, t) {
        return this.md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
    };
    MD5.prototype.md5_gg = function (a, b, c, d, x, s, t) {
        return this.md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
    };
    MD5.prototype.md5_hh = function (a, b, c, d, x, s, t) {
        return this.md5_cmn(b ^ c ^ d, a, b, x, s, t);
    };
    MD5.prototype.md5_ii = function (a, b, c, d, x, s, t) {
        return this.md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
    };
    /*
    * Add integers, wrapping at 2^32. This uses 16-bit operations internally
    * to work around bugs in some JS interpreters.
    */
    MD5.prototype.safe_add = function (x, y) {
        var lsw = (x & 0xFFFF) + (y & 0xFFFF);
        var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
        return (msw << 16) | (lsw & 0xFFFF);
    };
    /*
    * Bitwise rotate a 32-bit number to the left.
    */
    MD5.prototype.bit_rol = function (num, cnt) {
        return (num << cnt) | (num >>> (32 - cnt));
    };
    return MD5;
}());
__reflect(MD5.prototype, "MD5");
var Toast = (function (_super) {
    __extends(Toast, _super);
    function Toast(msg, w, h) {
        var _this = _super.call(this) || this;
        console.log("Toast:", msg);
        var bg = new egret.Bitmap(Toast._txtrToastBg);
        _this.x = w * .5;
        _this.y = h * .85;
        _this.addChild(bg);
        bg.$anchorOffsetX = bg.width / 2;
        // bg.$anchorOffsetY = bg.height/2;
        var tx = new egret.TextField;
        tx.multiline = true;
        tx.size = 30;
        tx.bold = true;
        tx.textColor = 0xFFFFFF;
        tx.stroke = 6;
        tx.strokeColor = 0;
        tx.text = msg;
        tx.fontFamily = "微软雅黑";
        tx.textAlign = egret.HorizontalAlign.CENTER;
        tx.width = w * 1.0;
        tx.x = bg.x;
        tx.y = bg.y + tx.size / 10;
        tx.anchorOffsetX = tx.width / 2;
        _this.addChild(tx);
        bg.height = 12 + tx.height;
        _this.alpha = 0;
        egret.Tween.get(_this)
            .to({ alpha: 1 }, 800, egret.Ease.quintOut)
            .wait(1600)
            .to({ alpha: 0 }, 1200, egret.Ease.quintIn).call(function () {
            if (_this.parent) {
                _this.parent.removeChild(_this);
            }
        });
        return _this;
    }
    Toast.init = function (cont, txtrToastBg) {
        console.log("Toast.init", txtrToastBg);
        this._cont = cont;
        this._txtrToastBg = txtrToastBg;
    };
    Toast.initRes = function (cont, img) {
        console.log("Toast.init", img);
        this._cont = cont;
        var loader = new egret.ImageLoader();
        //添加加载完成侦听
        loader.addEventListener(egret.Event.COMPLETE, function (event) {
            var loader = event.target;
            //获取加载到的纹理对象
            var bitmapData = loader.data;
            //创建纹理对象
            var texture = new egret.Texture();
            texture.bitmapData = bitmapData;
            this._txtrToastBg = texture;
            //创建 Bitmap 进行显示
            // this.addChild(new egret.Bitmap(texture));
        }, this);
        //开始加载
        loader.load(img);
    };
    Toast.show = function (msg) {
        if (this._cont) {
            var toast = new Toast(msg, 650, 1150);
            this._cont.addChild(toast);
        }
    };
    return Toast;
}(egret.DisplayObjectContainer));
__reflect(Toast.prototype, "Toast");
var WxUtils = (function () {
    function WxUtils() {
    }
    /**
     * 微信邀请
     * @param key 分享的标题
     * @param query 分享的内容
     */
    WxUtils.wxTogether = function (key, query) {
        together(key, query);
    };
    return WxUtils;
}());
__reflect(WxUtils.prototype, "WxUtils");
;window.Main = Main;